What is middleware in Node.js?
💡 Model Answer
Middleware in Node.js refers to functions that sit between the incoming request and the final request handler. Each middleware receives the request and response objects, and a next function to pass control to the next middleware. They are used for tasks such as logging, authentication, parsing request bodies, handling errors, and modifying request/response objects. In Express, middleware can be applied globally, to specific routes, or to route groups. For example, app.use(express.json()) parses JSON bodies for all routes. Middleware can be chained, and the order of registration determines the execution order.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500