app.use()
handles all the middleware functions.
What is middleware?
Middlewares are the functions which work like a door between two all the routes.
Like
app.use((req,res,next) =>{
console.log("middleware ran");
next()
})
app.get("/",(req,res) => {
console.log("Home route");
})
For instance:
app.use((req, res, next) => {
console.log("middleware ran");
next();
});
app.get("/", (req, res) => {
console.log("Home route");
});
When you visit /
route in your console the two message will be printed. The first message will be from middleware function.
IfIf there is no next()next()
function passed then only middleware function runs and other routes are blocked.