Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

@types/node-fetch 2.6.11

TypeScript definitions for node-fetch
Package summary
Share
0
issues
0
licenses
Package created
2 Aug 2016
Version published
16 Jan 2024
Maintainers
1
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does @types/node-fetch do?

The @types/node-fetch is a TypeScript declarations package for the popular node-fetch library. Its main purpose is to provide TypeScript developers with interface definitions for the node-fetch library functions and properties, making it easier to write type-safe code in TypeScript when using node-fetch. The node-fetch library is considered an ideal replacement for the native Node.js http and https modules when it comes to making HTTP requests, and using TypeScript with such a powerful library increases the reliability and readability of your code.

How do you use @types/node-fetch?

To use @types/node-fetch in your project, you should first install it from the NPM registry by running the command: npm install --save @types/node-fetch. Once installed, if you are using a TypeScript version that targets ES6 or above, the types will be automatically included through TypeScript's automatic type resolution. In case you're targeting ES5 or below, you need to manually include the types in your tsconfig.json file. Here's an example of how you might use node-fetch with TypeScript:

import fetch, { Headers, RequestInit, Response } from 'node-fetch';

async function fetchData(url: string): Promise<void> {
   let settings: RequestInit = { method: "Get" };
   let response: Response = await fetch(url, settings);
   let data: any = await response.json();
   console.log(data);
}

In this example, we import multiple types from node-fetch and use them to properly type our variables.

Where are the @types/node-fetch docs?

The documentation for @types/node-fetch package is found in the same place where its source code is maintained - the DefinitelyTyped project's GitHub repository. Follow this link to access the repository, then navigate to the types/node-fetch folder. Please note that TypeScript type definitions typically mirror the API of the libraries they refer to, so you might want to reference the node-fetch documentation as well for how to use the library itself.