How it works · web framework for Node.js

How Express works

A request comes in and passes through a list of functions, in order, until one of them answers.

Think of it like this. A mail room: each desk looks at the letter, then either answers it or passes it to the next desk.

  1. The app One function that Node calls for every request. It holds your settings and your routes. lib/application.js
  2. The router The list of functions, and the matching of each request’s path against them. pillarjs/routerits own package since Express 5
  3. The request Node’s request, with helpers added: the query, the IP, which content types are accepted. lib/request.js
  4. The response Node’s response, with helpers added: send, json, status, redirect, render. lib/response.js
  5. Views Finds a template file and the engine that can draw it. lib/view.js

Follow one thing through: A browser asks for GET /hello

  1. Node’s HTTP server calls the app, because the app is itself a function of (req, res).lib/express.js
  2. The app gives the request and response their extra helpers, then hands both to the router.lib/application.js
  3. The router goes down its list. Each entry checks whether the path and the method match.pillarjs/router
  4. A middleware that matches does its job (say, reading the JSON body) and calls next().
  5. Your handler for /hello matches and calls res.send("hi").lib/response.js
  6. send works out the content type and length, adds an ETag, and ends the response.lib/response.js

The clever bit: The app is just a function

express() returns a plain function, app(req, res, next), with the methods you know copied onto it. Because it is a function with the same shape as any handler, a whole Express app can be mounted inside another one with app.use("/admin", adminApp). Apps, routers and middleware are all the same kind of thing.

lib/express.js

Words you’ll meet

middleware
A function that sees every request on its way through, and can change it, answer it, or pass it on.
next()
How a function says “not mine, try the next one”. Calling it with an error skips ahead to the error handlers.
route
A path and a method (GET /hello) joined to the function that answers it.

Good questions to ask next

Open Express in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.

Take Express apart yourself.

Free and open source. Nothing to install, no account.

More projects, taken apart

Written by hand from the code as it was on 2026-11-02 (commit 43fca52). Express belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.