Question presented to candidate:
"You call fetch() in a Node.js script with zero imports, and it just works. What is actually handling that HTTP request under the hood, and how would you prove it's not some other, unrelated HTTP client?"
What a strong answer should cover:
- 📌 Interview term:
undici— a real, from-scratch HTTP/1.1 client built specifically for Node.js by the Node.js project itself (not a wrapper around the olderhttp/httpsmodules) — genuinely faster and more spec-compliant than Node's legacy HTTP client internals for many real workloads. - 📌 Verified, not assumed — direct, internal proof:
undicipublishes realdiagnostics_channelevents (undici:request:create,undici:client:sendHeaders,undici:request:headers) during a real HTTP request — subscribing to those channels and then calling the globalfetch()genuinely fired all three real events, direct, internal confirmation thatfetch()is implemented viaundici, not a separate, unrelated client. - The real, honest, verified nuance:
require("node:undici")itself genuinely threw a realERR_UNKNOWN_BUILTIN_MODULEon this Node version — confirmed via web search: Node's bundled-in undici (the one powering the globalfetch) is not separately importable asnode:undicion every Node version; the standaloneundicinpm package (installed separately) provides direct access to its fuller API (a real, configurableAgent, connection pooling, aMockAgentfor tests) beyond what the globalfetchalone exposes. - A precise answer names why Node adopted a purpose-built client rather than implementing
fetchon the pre-existinghttp/httpsmodules: those legacy modules were originally designed years beforefetch's Web-standard semantics existed, and buildingundicifrom scratch, spec-compliant with the WHATWG Fetch/Streams standards from the ground up, was genuinely more direct than retrofitting decades-old internals to match a browser-originated API. - A precise answer scopes what
fetch()alone does not expose that the fullundicipackage does: real, fine-grained connection-pool tuning, a realAgentwith configurable keep-alive/pipelining behavior, and real request/response interceptors — a precise answer names these as reasons to reach for the separateundicipackage directly, rather than assuming the globalfetchalone covers every real, advanced HTTP-client need.
Clarifying questions expected:
- "Does this specific use case need anything beyond what the plain global fetch() API already exposes — connection-pool tuning, interceptors, a MockAgent for tests — that would justify installing and importing the separate undici package directly?"
- "Is the target Node version's global fetch implementation confirmed to be Stable in the actual deployed version, given it moved from experimental to Stable across recent Node releases?"
Code / implementation expected: Yes — real, internal proof that a plain global fetch() call genuinely fires undici's own diagnostics_channel events is the concrete, convincing proof of exactly what's handling the request under the hood, beyond simply citing documentation.