1 Install HTTP request logger middleware morgan
$ npm install morgan
2 Import middleware
const express = require('express');
const logger = require('morgan');
const app = express();
app.use(logger('dev'));
...
3 Result
const express = require('express');
const app = express();
// An example middleware function
let a_middleware_function = function(req, res, next) {
// ... perform some operations
next(); // Call next() so Express will call the next middleware function in the chain.
}
// Function added with use() for all routes and verbs
app.use(a_middleware_function);
// Function added with use() for a specific route
app.use('/someroute', a_middleware_function);
// A middleware function added for a specific HTTP verb and route
app.get('/', a_middleware_function);
app.listen(3000);
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction