Morgan is a middleware function for logging information about the http request/response in a server application.
$ npm install morgan
const morgan = require('morgan'); app.use(morgan('dev'));
Morgan takes two arguments: format and options.
You can defined your own format string or use the predefined formats. I like to keep things simple while learning a new concept hence i opted for the predefined formats. Here are a few predefined formats.
tiny- logs out minimal information about the request. status.
devlogs out concise output with color coded status.
combinedlogs out Standard Apache combined log output (A lot of information that you probably don't care about).
For more formats refer to the documentation.
Valid option (objects) accepted by morgan.
immediate- information is logged on request instead of on response
skip- determines if logging is skipped
stream- Output stream for writing log lines
More on this in the documentation