How it works...

Middleware and route configurations are very similar in Express. Route configurations are a specialized type of middleware based around Express' router object. Unlike Express route configurations, custom middleware can take any properties we want. Custom middleware acts as a closure that associates your custom parameters with Express's callback to handle the request:

middleware: function (params) {  return function (req, res, next) {    // this call back use both params & Express objects  }}

By placing our middleware in Express's app.use method, we are wiring our middleware to a route in the same manner as our Express route configurations. We can also take this a step farther by nesting our middleware in an existing app.use configuration: ...

Get MEAN Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.