morgan nodejs github

Installing morgan in Node.js

npm install morgan

This command installs the morgan package from npm, the Node.js package manager.

Requiring morgan in a Node.js application

const morgan = require('morgan');

This line of code imports the morgan package into the Node.js application, allowing it to be used within the application.

Using morgan as middleware in an Express application

app.use(morgan('dev'));

In this code, morgan is used as middleware in an Express application, with the 'dev' format specified to log requests in a concise, development-friendly format.