The next()
function is used to pass control to the next middleware function in the stack. If the current middleware does not end the request-response cycle, next()
must be called; otherwise, the request will hang. Example:
app.use((req, res, next) => {
console.log('Middleware 1');
next(); // Pass to next middleware
});
app.use((req, res) => {
res.send('Hello from Middleware 2!');
});