Is there a useful difference between app.all(\'*\', ... )
and app.use(\'/\', ...)
in Node.JS Express?
There are two main differences:
1. pattern matching (answer given by Palani)
2. next(route)
won't work inside the function body of middleware loaded using app.use
. This is stated in the link from the docs:
NOTE: next('route') will work only in middleware functions that were loaded by using the app.METHOD() or router.METHOD() functions.
Link: http://expressjs.com/en/guide/using-middleware.html
The working effect of next('route')
can be seen from the following example:
app.get('/',
(req,res,next)=>{console.log("1");
next(route); //The code here skips ALL the following middlewares
}
(req,res,next)=>{next();}, //skipped
(req,res,next)=>{next();} //skipped
);
//Not skipped
app.get('/',function(req,res,next){console.log("2");next();});