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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.