talira

node-fetch

A light-weight module that brings the Fetch API to Node.js

open sourceMITself-hostablefree

node-fetch looks abandoned: nothing has changed since August 2023, and its makers haven't said it has ended.

No commits on the main or 2.x branches and no npm release since August 2023; the makers haven't announced an end.

node-fetch implements the browser's window.fetch API on top of Node.js's own http module, for code that wants the same fetch calls on the server. It uses native promises and Node.js streams for request and response bodies, decodes gzip, deflate and brotli, and adds a redirect limit, a response size limit and typed errors; its docs list where it differs from browser fetch. Version 3 is ESM only, while v2 stays CommonJS-compatible. Node.js now has fetch built in, and the project has had no release since August 2023; Ky, ofetch and axios are maintained alternatives.

Problems it solves

  • use the same fetch() calls in old Node.js versions that don't have fetch built in
  • polyfill globalThis.fetch, Headers, Request and Response in a Node.js app
  • stream a fetch response body to a file with Node.js streams
  • limit how many redirects a server-side fetch follows and how big the response can be
  • send a file as a stream in a POST body from Node.js

Features

  • window.fetch-compatible API
  • native promises and async functions
  • Node.js streams for request and response bodies
  • gzip, deflate and brotli decoding
  • redirect limit and response size limit
  • FetchError and AbortError types
  • AbortSignal cancellation
  • custom http.Agent
  • TypeScript types

Limitations

  • Doesn't load with require() in CommonJS from v3: version 3 is ESM only, and v2 stays CommonJS-compatible1
  • Doesn't keep cookies between requests: there's no cookie store, so you read Set-Cookie headers yourself2
  • Doesn't cache responses: there's no built-in HTTP caching2

Capabilities

Has an APIplan not known

Alternatives

The same job

These do what node-fetch does.

  1. undici An HTTP/1.1 client, written from scratch for Node.js
  2. ofetch A better fetch API. Works on node, browser, and workers.
  3. Got Human-friendly and powerful HTTP request library for Node.js
  4. SuperAgent Ajax for Node.js and browsers (JS HTTP client)
  5. axios Promise based HTTP client for the browser and node.js
  6. Ky Tiny & elegant JavaScript HTTP client based on the Fetch API

Compare node-fetch with the top 3