Need Assistance?

support@tutorialshub.in

Middleware Architecture

What is Middleware? (req, res, next)

ADVERTISEMENT
Express.js Free Lesson
5 min read
ADVERTISEMENT

Middleware functions are functions that have access to the request object (req), the response object (res), and the next function in the application's request-response cycle.

What Middleware Can Do

  • Execute any code (e.g., logging, timing, analytics).
  • Modify req or res objects (e.g., attach req.user).
  • End the request-response cycle early (e.g., return 401 Unauthorized).
  • Call next() to pass control to the next middleware or route handler.

Important: Middleware runs in the exact order you register it with app.use().

ADVERTISEMENT
Hi, I'm Tuby! Here to help you