What can an Express middleware do?
Modify req (e.g., set req.user from JWT), send a response and end the cycle, call next() to pass to the next middleware, or call next(err) to jump to the error handler.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in What Is Express Middleware? Explained With Examples
A function with the signature (req, res, next) that runs on requests. It can modify req, send a response, call next to continue, or call next(err) to jump to the error handler. Almost everything in Express is middleware.
App-level (app.use), router-level (router.use), built-in (express.json), third-party (cors, helmet), and error-handling (four parameters: err, req, res, next).
Express runs middlewares in the order you add them. Add body parser before routes that need req.body. Add auth before protected routes. Add the error handler last. Wrong order causes silent bugs.
Still have questions?
Browse all our FAQs or reach out to our support team
