You can also create your own middleware function like
app.use( function(req, res, next) {
// your code
next();
})
It contains three parameters req
, res
, next
You can also use it for authentication and validation of input params to keep your
controller clean.
next()
is used for go to next middleware or route.
You can send the response from middleware