Skip to main content
formatting
Source Link
Mike
  • 14.5k
  • 31
  • 118
  • 174

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.

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");
})

When you visit / route in your console the two message will be printed. The first message will be from middleware function.
If there is no next() function passed then only middleware function runs and other routes are blocked.

app.use() handles all the middleware functions.
What is middleware?
Middlewares are the functions which work like a door between two all the routes.

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. If there is no next() function passed then only middleware function runs and other routes are blocked.

Source Link

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");
})

When you visit / route in your console the two message will be printed. The first message will be from middleware function.
If there is no next() function passed then only middleware function runs and other routes are blocked.