What Express Does
- Routing — path, method, regex matching
- Middleware — composable request/response pipeline
- Request/response — enhanced req/res objects
- Error handling — centralized error middleware
- Static files —
express.static()built in - Template engines — Pug, EJS, Handlebars via
app.engine() - JSON parsing —
express.json()middleware - Cookies/sessions — via cookie-parser and express-session
- CORS — via cors middleware
- Express 5 — native async error handling (upcoming)
Architecture
Middleware stack: each app.use() adds a function to the pipeline. Request enters, flows through middleware in order, and hits the matching route handler. Router is a mini-app with its own middleware and routes. Error middleware has 4 arguments (err, req, res, next).
Self-Hosting
# Production
NODE_ENV=production node server.js
# PM2
npm i -g pm2
pm2 start server.js -i max
pm2 startup && pm2 save
# Docker
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
CMD ["node", "server.js"]Key Features
- Minimal and unopinionated
- Middleware-based architecture
- Huge middleware ecosystem
- Template engine support
- Static file serving
- HTTP utility methods
- Easy to learn
- Express Generator for scaffolding
- Works with any Node.js version
Comparison
| Framework | Speed | Opinionated | TS |
|---|---|---|---|
| Express | OK | No | via @types |
| Fastify | Fast | Slightly | Yes |
| Hono | Fast | No | Yes |
| Koa | OK | No | via @types |
| NestJS | OK (Express/Fastify) | Yes | Yes |
FAQ
Q: Is Express outdated? A: No. Fastify and Hono perform better, but Express has the largest ecosystem, the most tutorials, and the richest middleware. Many production apps still use it and run stably. Express 5 is under development.
Q: TypeScript support?
A: With @types/express you get full types. Many projects use ts-node or tsx during development.
Q: Error handling? A: Express 4 requires wrapping async handlers with try-catch or using express-async-errors. Express 5 natively catches async throws and forwards them to error middleware.
Sources
- Docs: https://expressjs.com
- GitHub: https://github.com/expressjs/express
- License: MIT