Socket
Socket
Sign inDemoInstall

@types/node-fetch

Package Overview
Dependencies
6
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/node-fetch

Stub TypeScript definitions entry for node-fetch, which provides its own types definitions


Version published
Maintainers
1
Weekly downloads
11,973,747
decreased by-1.25%
Install size
7.32 MB

Weekly downloads

Package description

What is @types/node-fetch?

The @types/node-fetch npm package provides TypeScript type definitions for the node-fetch library, which is a light-weight module that enables making HTTP requests in Node.js environments similar to the Fetch API provided in the browser. This package does not contain functionality by itself but offers type support for using node-fetch in TypeScript projects, ensuring type safety and IntelliSense in IDEs.

What are @types/node-fetch's main functionalities?

Making HTTP GET Requests

This code demonstrates how to make a simple HTTP GET request to retrieve data from a JSON placeholder API and log it to the console. The @types/node-fetch package provides type definitions for the response object and its methods.

import fetch from 'node-fetch';

async function getTodo() {
  const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
  const data = await response.json();
  console.log(data);
}

getTodo();

Making HTTP POST Requests

This example shows how to make an HTTP POST request to create a new resource on a JSON placeholder API. It demonstrates setting the request method, body, and headers. The @types/node-fetch package ensures that the properties and methods used are correctly typed.

import fetch from 'node-fetch';

async function createTodo() {
  const response = await fetch('https://jsonplaceholder.typicode.com/todos', {
    method: 'POST',
    body: JSON.stringify({
      title: 'foo',
      body: 'bar',
      userId: 1
    }),
    headers: { 'Content-Type': 'application/json' }
  });
  const data = await response.json();
  console.log(data);
}

createTodo();

Other packages similar to @types/node-fetch

Readme

Source

This is a stub types definition for @types/node-fetch (https://github.com/node-fetch/node-fetch).

node-fetch provides its own type definitions, so you don't need @types/node-fetch installed!

FAQs

Last updated on 03 Sep 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc