From 9b7348625de01f1fabe970816a058f8de449eb7b Mon Sep 17 00:00:00 2001 From: akachi10 <38939292+akachi10@users.noreply.github.com> Date: Sun, 15 Feb 2026 20:05:38 +0800 Subject: [PATCH] doc: add section about fetch() differences from standard Added new section to document how Node.js fetch differs from standard. Covers async iterable support, cookies handling, and forbidden headers. Fixes #52163 --- doc/api/globals.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/api/globals.md b/doc/api/globals.md index f7d7dd33dd3f0a..c44ed0f0e63fa4 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -585,6 +585,40 @@ The following globals are available to use with `fetch`: * [`Request`](https://nodejs.org/api/globals.html#request) * [`Response`](https://nodejs.org/api/globals.html#response). +### Differences from the standard + +While Node.js's `fetch()` implementation is browser-compatible, there are some notable differences from the standard Fetch API: + +#### AsyncIterable Response body + +Node.js extends the standard `Response` constructor to accept async iterables: + +```mjs +import { Readable } from 'node:stream'; + +const stream = Readable.from(['Hello', ' ', 'World']); +const response = new Response(stream); +const text = await response.text(); +console.log(text); // 'Hello World' +``` + +This is a Node.js-specific extension and is not part of the standard Fetch API. + +#### Cookies handling + +Node.js `fetch()` does not automatically handle cookies. Unlike browsers, cookies are not stored or sent automatically with requests. If you need cookie support, you must handle it manually using the `Headers` API. + +#### No forbidden headers + +The standard Fetch API restricts certain headers (called "forbidden headers") from being set by user code for security reasons. Node.js `fetch()` does not enforce these restrictions, allowing you to set any header, including: + +* `Host` +* `Connection` +* `Content-Length` +* And other headers typically restricted in browsers + +This gives you more flexibility in server-side scenarios where such restrictions are not necessary. + ## Class: `File`