mardi 29 juin 2021

Why middleware is executing even I do not call next() method after sending response in NodeJS?

I have following code :

use("/joker", (req, res, next) => {
      console.log("In the middleware !");
      res.send('<h1>Hello Joker !</h1>');
    });
    app.use("/", (req, res, next) => {
      console.log("In the next middleware !");
      res.send("<h1>Hello Alien !</h1>");
    });

This gives the following output on console :

In the middleware !
In the next middleware !
In the middleware !
In the next middleware !

And prints Hello Joker on webpage.

Can you please explain why that text is logged from next middleware even if I did not called next() method and also why they are printing twice in console?




Aucun commentaire:

Enregistrer un commentaire