Node.js Internals7h estimated

The Node HTTP Module Internals

Difficulty
Importance

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

Used in

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