Is there a difference between
app.use('*', function (req, res, next) {
});
and...
app.all('*', function (req, res, next) {
});
Is there a difference between
app.use('*', function (req, res, next) {
});
and...
app.all('*', function (req, res, next) {
});
app.all()
references the application router like post
or get
, while app.use()
simply references the applications middleware. app.use()
is better for more globally defined statements that you want persistent through your entire application.
app.use takes only one callback function and its meant for Middleware. Middleware usually don't handle request and response, (technically they can) they just process input data, and hand over it to next handler in queue.
app.use([path], function) app.all take multiple callbacks, and meant for routing. with multiple callbacks you can filter requests and send responses. Its explained in Filters on express.js
app.all(path, [callback...], callback)