Morgan is a middleware function for logging information about the http request/response in a server application.
Installation
$ npm install morgan
Use
const morgan = require('morgan');
app.use(morgan('dev'));
Arguments.
Morgan takes two arguments: format and options.
FORMATS
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.
app.use(morgan('tiny'));
-
dev
logs out concise output with color coded status.
app.use(morgan('dev'));
-
combined
logs out Standard Apache combined log output (A lot of information that you probably don't care about).
app.use(morgan('combined'));
For more formats refer to the documentation.
OPTIONS
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
Day 39
Top comments (0)