Loading
A function that runs between receiving a request and sending a response — like a series of checkpoints a package goes through before delivery.
A function with access to the request object, response object, and the next() function in the Express pipeline. Middleware can modify req/res, end the cycle (res.send()), or pass control to the next function. Common uses include logging, authentication, and body parsing.
Express middleware follows the Connect-style (req, res, next) contract. The stack is executed linearly; calling next() with no argument invokes the next matching layer, while next(err) skips to the next error-handling middleware (4-arity). Middleware can be app-level (app.use), router-level (router.use), or error-handling. Because middleware mutates shared req/res objects, ordering is critical — body parsers must precede route handlers that read req.body.