Express is a web framework for Node.js. It wraps Node's built-in http module with three things that raw http.createServer does not give you: a composable middleware pipeline, a router that maps method-plus-path patterns to handler functions, and extended request/response objects (req.query, res.json(), res.sendFile(), and about fifty other members). The package describes itself in one line in package.json: "Fast, unopinionated, minimalist web framework".
"Minimalist" is measurable here. The entire runtime is six files in lib/ totalling about 2,800 lines. Express 5 moved most historical subsystems into standalone packages -- routing lives in router, body parsing in body-parser, file serving in send and serve-static -- and this repo is the thin layer that composes them behind one API.
Who uses it and for what
Express has been the default HTTP layer of the Node ecosystem since 2010. The common shapes of an Express app, all present in this repo's examples/ directory:
- JSON APIs -- route handlers ending in
res.json(), withexpress.json()parsing request bodies (examples/web-service). - Server-rendered sites -- template engines wired through
app.engine()andres.render()(examples/mvc,examples/ejs). - Static file serving --
express.static()in front of a directory of assets (examples/static-files). - Composable sub-applications -- routers and whole apps mounted under path prefixes to split a service into modules (
examples/multi-router,examples/vhost).
The smallest complete app, from examples/hello-world/index.js:
var app = module.exports = express()
app.get('/', function(req, res){
res.send('Hello World');
});
What is actually in this repository
Express 5.2.1 ships exactly four things to npm (the files field in package.json): LICENSE, Readme.md, index.js, and lib/. Everything else -- test/ (78 test files), examples/ (26 runnable apps), benchmarks/ -- is development material. index.js is one line: module.exports = require('./lib/express').
The six runtime files:
| File | Role |
|---|---|
lib/express.js |
Factory: createApplication(), plus re-exports (express.json, express.static, express.Router, ...) |
lib/application.js |
The app object: settings, app.use, HTTP verb methods, app.listen, app.render |
lib/request.js |
Request prototype layered over http.IncomingMessage |
lib/response.js |
Response prototype layered over http.ServerResponse |
lib/view.js |
Template lookup and engine loading for res.render |
lib/utils.js |
Setting compilers (compileETag, compileQueryParser, compileTrust) and type helpers |
Where to go next
- Evaluating or learning Express itself: read the request lifecycle to see everything that happens between
app.listenand a byte hitting the socket. - Contributing to this repo: start at onboarding, which walks through setup, the test workflow, and a safe first change.
- Debugging app behavior (why did I get a 304? which setting controls this?): the app settings reference and request and response extensions.
- Understanding the dependency tree: the technologies section documents each direct dependency with the exact file in this repo that imports it.
- Looking for working code to copy: the cookbook extracts patterns from
examples/.