I am working with Nodejs and i am using express js,And right now i am using middleware function,In middleware function we have three main parameters "req,res,next", In "next" parameter...go to next "middleware function"
- I have three middleware function but i call/use/execute only "first middleware function", so after execute first middleware ( reach to "next parameter" in first middleware) if "next parameter" go to "next middleware function" then why not "middleware2" and "middleware3" execute automatically ? Here is my current code
const express = require('express');
const app = express();
// First middleware function
const middleware1 = (req, res, next) => {
console.log('This is middleware 1');
next(); // Calling next() passes control to the next middleware function
};
// Second middleware function
const middleware2 = (req, res, next) => {
console.log('This is middleware 2');
next(); // Calling next() passes control to the next middleware function
};
// Third middleware function
const middleware3 = (req, res, next) => {
console.log('This is middleware 3');
next(); // Calling next() passes control to the next middleware function
};
app.use(middleware1);
// Route handler
app.get('/', (req, res) => {
res.send('Hello, World!');
});
app.listen(3000, () => {
console.log('Server listening on port 3000');
});