Introduction to Middleware
Swipe to show menu
Middleware is a function that runs between receiving a request and sending a response.
It has access to the request, the response, and a special function called next.
app.use((req, res, next) => {
console.log('Request received');
next();
});
When a request comes in, middleware runs first. After it finishes, it calls next() to pass control to the next step.
The flow looks like this:
Request → Middleware → Route → Response
Middleware is used to process requests before they reach your route logic.
Common use cases include:
- Logging Requests;
- Parsing Data;
- Checking Authentication.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Introduction to Middleware
Middleware is a function that runs between receiving a request and sending a response.
It has access to the request, the response, and a special function called next.
app.use((req, res, next) => {
console.log('Request received');
next();
});
When a request comes in, middleware runs first. After it finishes, it calls next() to pass control to the next step.
The flow looks like this:
Request → Middleware → Route → Response
Middleware is used to process requests before they reach your route logic.
Common use cases include:
- Logging Requests;
- Parsing Data;
- Checking Authentication.
Thanks for your feedback!