docs: add Getting Started guide by AliMahmoudDev · Pull Request #5371 · nodejs/undici (original) (raw)
addresses #2208
adds a Getting Started guide covering the most common undici use cases:
fetchfor simple requestsrequest/stream/pipelinefor more control- when to use Client vs Pool vs Agent
- timeouts and error handling
- common patterns (proxies, mocking, global install)
- links to relevant API docs and best practices for deeper reading
Codecov Report
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.25%. Comparing base (a8ea6f2) to head (44afc12).
Additional details and impacted files
@@ Coverage Diff @@ ## main #5371 +/- ##
Coverage 93.25% 93.25%
Files 110 110
Lines 36738 36738
- Hits 34259 34260 +1
- Misses 2479 2478 -1
☔ View full report in Codecov by Harness.
📢 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.
| import { createWriteStream } from 'node:fs' |
|---|
| const res = await fetch('https://example.com/large-file.zip') |
| Readable.fromWeb(res.body).pipe(createWriteStream('./file.zip')) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a few problems. The actual solution is to use pipeline from node:stream with res.body and createWriteStream.
| | `fetch` | Quick requests, standard API compatibility, JSON/form bodies | | | --------------- | ------------------------------------------------------------------ | | | | `request` | Maximum throughput, reading response headers, fine-grained control | | | | `stream` | Piping responses directly to a writable stream | | | | `pipeline` | Streaming request bodies combined with streaming responses | |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not document this here, and ideally not even stream.
… streaming, remove stream/pipeline docs
pushed -- added a Request object example, switched the streaming snippet to use pipeline from node:stream/promises, and removed the stream/pipeline sections and the method comparison table.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This was referenced
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})