The Node HTTP Module Internals
The problem
Every Node web framework (Express, Fastify, Koa) is built on top of something — understanding what that underlying layer actually does, request by request, demystifies what a framework is really adding versus what was already there in Node itself.
Why now
Building an HTTP server already covered the accept-parse-respond loop in the abstract; this topic is Node's specific implementation of that loop, built directly on libuv's event loop and streams — showing exactly how an incoming request becomes a readable stream and an outgoing response becomes a writable one.
Mental model
Node's http module hands you a request object that's a readable stream (the body arrives in chunks, exactly as streams-and-backpressure describes) and a response object that's a writable stream you write to and must explicitly end() — a framework like Express doesn't replace this, it wraps it with routing, middleware, and convenience methods layered on top of these same two streams.
Requires
- Building an HTTP ServerBackend Engineering
This topic is Node's concrete implementation of exactly the accept-parse-respond loop building-an-http-server already covers generically; you need that general model before Node's specific request/response object shapes add anything beyond restating it.
- libuv & the Event Loop PhasesNode.js Internals
Incoming HTTP connections and data arrive as events delivered through libuv's poll phase already covered; you need that event-delivery model to understand when and how request data actually becomes available to your code.
Used in
- Every Node.js web framework, built as a layer on top of the raw http module
- Understanding what Express's req and res objects actually are underneath their convenience methods
- Debugging low-level issues (a response that never ends, a request body that never fully arrives)
- Writing minimal servers or proxies without the overhead of a full framework
Projects
- Build a small server using only Node's raw http module (no framework) that correctly reads a POST request body by listening for 'data' and 'end' events, then responds
- Trace an Express request through to the raw http module by inspecting req/res inside an Express handler and confirming they're the same stream-based objects Node's http module provides
Examples
- http.createServer((req, res) => { ... }) hands you req as a readable stream you must accumulate chunks from to get a full body — there's no built-in req.body without a framework or manual parsing
- Forgetting to call res.end() leaves an HTTP response hanging forever, because Node has no way to know the response is complete until you explicitly say so
Resources
Mastery checklist
- I can build a minimal server using Node's raw http module without a framework
- I can manually read a full request body by accumulating stream chunks
- I can explain why a response must be explicitly ended
- I can explain what a framework like Express adds on top of the raw http module