The mental model: app, router, middleware
An Express app is a thin pipeline. A request walks through an ordered list of middleware functions until one of them ends the response. Routes are middleware too โ they're just middleware that match a method + path.
import express from 'express';
const app = express();
app.use(express.json()); // middleware: parse JSON body
app.get('/health', (req, res) => res.json({ ok: true }));
app.listen(3000);
A Router is a sub-app you .use() mount under a prefix (app.use('/api', apiRouter)). Everything else โ auth, logging, error handling โ is some function with the signature (req, res, next) plugged into that pipeline at the right spot.
