Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@types/node-fetch
Advanced tools
Stub TypeScript definitions entry for node-fetch, which provides its own types definitions
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.
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();
Axios is a promise-based HTTP client for the browser and Node.js. It provides an easy-to-use API for making HTTP requests and has built-in support for request and response interceptors, transforming request and response data, and automatic JSON data transformation. Unlike @types/node-fetch, Axios does not require an additional types package for TypeScript support as it includes its own type definitions.
Got is a human-friendly and powerful HTTP request library for Node.js. It supports retries, streams, and pagination, among other features. Got is designed to be more comprehensive than node-fetch, offering more built-in functionalities like caching and request retries. TypeScript types are included in the package, so there's no need for an additional @types package.
Superagent is a light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It works with both Node.js and browser environments. Like Axios, it has built-in type definitions, eliminating the need for a separate types package.
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
TypeScript definitions for node-fetch
The npm package @types/node-fetch receives a total of 7,473,716 weekly downloads. As such, @types/node-fetch popularity was classified as popular.
We found that @types/node-fetch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.