Skip to content

docs: clarify when to install undici vs using Node's built-in fetch#4868

Merged
mcollina merged 2 commits intonodejs:mainfrom
travisbreaks:docs/undici-vs-builtin-fetch
Mar 8, 2026
Merged

docs: clarify when to install undici vs using Node's built-in fetch#4868
mcollina merged 2 commits intonodejs:mainfrom
travisbreaks:docs/undici-vs-builtin-fetch

Conversation

@travisbreaks
Copy link
Contributor

This relates to...

#4066

Changes

While PR #4245 added an "Undici vs. Fetch" section to the README, this PR adds a dedicated best-practices guide page within the docsify documentation site, making the information discoverable from the docs sidebar.

The new guide at docs/docs/best-practices/undici-vs-builtin-fetch.md covers:

  • Background: How Node.js bundles undici to power its built-in fetch, Request, Response, Headers, and FormData globals
  • When you do NOT need to install undici: Standard Fetch API usage on Node.js v18+, zero-dependency scenarios, cross-runtime libraries
  • When you SHOULD install undici: Advanced APIs (request, stream, pipeline), connection pooling (Client, Pool, BalancedPool), proxy support (ProxyAgent), testing/mocking (MockAgent), interceptors, or getting a newer version than what Node.js bundles
  • Version compatibility table: Which undici version ships with which Node.js release
  • How to override the built-in fetch with the installed version
  • Further reading links to relevant API docs

Also adds the guide to the docsify sidebar under "Best Practices" (first entry, as the issue requested it be "near the top").

Status

Co-authored-by: Egger egger@horny-toad.com

Adds a best-practices doc page explaining when to install undici from npm versus relying on Node.js's built-in fetch. Covers advanced APIs, connection pooling, proxy support, mocking, interceptors, and version compatibility. Also adds a sidebar link so the guide is discoverable in the docs site. Closes nodejs#4066 Co-authored-by: Egger <egger@horny-toad.com>
Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just smaller details


### Proxy support

`ProxyAgent` and `EnvHttpProxyAgent` handle HTTP(S) proxying, which is not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvHttpProxyAgent is currently supported by native fetch.

|---|---|---|
| v18.x | ~5.x | `fetch` is experimental (behind `--experimental-fetch` in early v18) |
| v20.x | ~6.x | `fetch` is stable |
| v22.x | ~6.x / ~7.x | `fetch` is stable |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add v24?

- Add cross-platform interoperability (browsers + runtimes) as a reason to use the built-in fetch API - Update proxy support section to reflect that EnvHttpProxyAgent is now supported by native fetch in Node.js v22.21.0+ and v24.0.0+ via --use-env-proxy, while noting undici's ProxyAgent still offers programmatic dispatcher-based control - Add Node.js v24 row to the version compatibility table Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 49d62da into nodejs:main Mar 8, 2026
34 of 35 checks passed
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.02%. Comparing base (bfeacd0) to head (bd2e65a).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@ ## main #4868 +/- ## ========================================== - Coverage 93.14% 93.02% -0.12%  ========================================== Files 109 112 +3 Lines 34254 35176 +922 ========================================== + Hits 31905 32723 +818  - Misses 2349 2453 +104 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@github-actions github-actions bot mentioned this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants