O'Reilly logo
  • Patrick S thinks this is interesting:

app.use() method from the Express.js API. This is applicable to both third-party middleware and in-house middleware.

The method app.use() has one optional string parameter path and one mandatory function parameter callback. For example, to implement a logger with a date, time, request method, and URL, we use the console.log() method:

// Instantiate the Express.js app
app.use(function(req, res, next) {
  console.log('%s %s — %s', (new Date).toString(), req.method, req.url);


Cover of Pro Express.js


using Middleware & 'mounting' example