Internals Reference · Express v5.x

The anatomy
of Express

Strip away the tutorials and Express is three things: a function you hand to Node's HTTP server, a stack of Layer objects it walks per request, and a pair of augmented req/res prototypes. Click any block in the lifecycle, any card below, or any highlighted term to see exactly how it works.

11
Components
5
lib/ files
3
Core objects
∞
Middleware
01 — Lifecycle

One request, top to bottom.

A request enters Node's HTTP server and is handed to app — which is literally a function. From there it descends through app.handle() into the router, gets matched against a stack of Layers, dispatched to a Route, and finally answered by a handler calling res.send(). Click any node.

Request flow · top → bottom
Node / HTTP App Router Route
Wire Node App Handle Router Stack Route Reply Incoming HTTP request GET /users/42 Node http.Server http.createServer(app) app(req, res) the express() function · just a callback app.handle() augment prototypes · init locals req extension lib/request.js res extension lib/response.js router.handle() iterate the Layer stack Stack of Layers match(path) · extract params handle(req,res,next) · next() compiled by path-to-regexp Error Layer (err,req,res,next) 4-arg signature Route.dispatch() method-specific handler stack handler(req, res) your route logic · controller → service res.send() → Response res.json() · headers · status · body
02 — Internals

Eleven components, source-level.

Each card maps to a real file or concept in the Express source tree. Click for the deep cut: what it actually does, the code that does it, how it talks to its neighbours, and a glossary of the terms involved. Several cards carry interactive walkthroughs.

Back to JIT-Atlas