An HTTP/1.1 client, written from scratch for Node.js
open sourceMITself-hostablefree
undici is the Node.js project's HTTP client, written from scratch, and the engine behind the fetch() built into Node.js since v18. Its own request, stream and pipeline APIs are faster than its standards-compliant fetch, and it exposes the dispatchers underneath: Client (one origin, with keep-alive, optional pipelining and HTTP/2 when the server picks it through ALPN), Pool, BalancedPool and Agent, plus ProxyAgent, EnvHttpProxyAgent, Socks5ProxyAgent and RetryAgent. Composable interceptors add redirects, retries, DNS caching, decompression, request deduplication and an RFC 9111 response cache with in-memory or SQLite storage, and MockAgent and SnapshotAgent fake or replay HTTP in tests. The npm package can be newer than the copy bundled in Node, adds ProxyAgent, MockAgent and interceptors to fetch, and ships WebSocket and EventSource clients; it's MIT-licensed, with release lines that follow Node's LTS schedule. Its name is Italian for eleven, from HTTP/1.1.
Problems it solves
- Node's built-in http module is slow and awkward for making lots of outgoing requests from my service
- make thousands of HTTP requests per second from Node.js to a few backend services with connection pooling
- the fetch built into Node is stuck on an old version and I need newer fixes and options
- send fetch requests from Node.js through a corporate HTTP proxy
- make my Node app honour HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables for all fetch calls
- route Node.js HTTP traffic through a SOCKS5 proxy
- mock outgoing HTTP calls in my Node.js tests without starting a fake server
- record real API responses once and replay them in CI so tests don't hit the network
- retry failed HTTP requests from Node with backoff without wrapping every call
- cache HTTP responses in my Node service following Cache-Control and ETag rules, in memory or on disk
- Node fetch hangs or runs out of sockets because response bodies aren't consumed
- set keep-alive timeouts and per-origin connection limits for outgoing HTTP in Node
- stream a large HTTP download straight into a file in Node without buffering it all in memory
- talk HTTP to a local daemon over a Unix domain socket or Windows named pipe from Node.js
- send HTTP/2 requests from Node.js with multiplexing to an API that prefers it
- use a client certificate for mutual TLS on outgoing requests from Node
- connect to a WebSocket server from Node.js without adding the ws package
- subscribe to a server-sent events stream from a Node script
- deduplicate identical in-flight GET requests in my Node service so the upstream sees one
- trace and log every outgoing HTTP request in Node with diagnostics channels
- stop fetch connections failing on dual-stack hosts where IPv6 doesn't work
Features
- request, stream, pipeline, connect and upgrade APIs
- WHATWG fetch implementation, the one built into Node.js since v18
- Client, Pool, BalancedPool, RoundRobinPool and Agent dispatchers with keep-alive
- HTTP/2 when the server prefers it through ALPN (allowH2), and H2CClient for cleartext HTTP/2
- optional HTTP/1.1 pipelining
- ProxyAgent, EnvHttpProxyAgent (http_proxy, https_proxy, no_proxy) and Socks5ProxyAgent
- RetryAgent and retry handler
- interceptors: redirect, retry, dump, dns, cache, decompress, responseError and deduplicate
- RFC 9111 HTTP cache with in-memory or SQLite stores
- decompression of gzip, Brotli, deflate and zstd responses
View 9 more
- MockAgent, MockPool, MockClient and call history for tests
- SnapshotAgent that records and replays responses (experimental)
- WebSocket and EventSource clients
- cookie helpers and CacheStorage
- Unix domain sockets and Windows named pipes (socketPath)
- every tls.connect() option, including client certificates
- diagnostics channel support
- install() to replace the global fetch, Headers, Request, Response and FormData
- release lines aligned with Node.js LTS (8.x bundled in Node 26)
Limitations
- Doesn't work without WebAssembly: its HTTP/1 parser needs it, so requests fail with ERR_WEBASSEMBLY_NOT_SUPPORTED under --jitless1
- Doesn't support the Expect: 100-continue request header: it sends the body at once and ignores 100 Continue1
- Doesn't implement CORS in fetch: no preflight requests or Access-Control-Allow-Origin checks1
Capabilities
| Has an API | plan not known |
|---|
Alternatives
The same job
These do what undici does.
- node-fetch A light-weight module that brings the Fetch API to Node.js
- axios Promise based HTTP client for the browser and node.js
- Got Human-friendly and powerful HTTP request library for Node.js
- SuperAgent Ajax for Node.js and browsers (JS HTTP client)
- Ky Tiny & elegant JavaScript HTTP client based on the Fetch API
- ofetch A better fetch API. Works on node, browser, and workers.
