🛠️
Utility5M+/wkMIT

morgan

Morgan is an HTTP request logger middleware for Node.js that records incoming request details in a configurable log format. Named after Dexter Morgan, the libra

Installation

npm
npm install morgan
yarn
yarn add morgan
pnpm
pnpm add morgan

Import

ESM
import morgan from 'morgan';

Quick Example

usage
import express from 'express';
import morgan from 'morgan';

const app = express();
app.use(morgan('dev'));
// Output: GET /api/users 200 12.345 ms

// Or use combined format for production:
// app.use(morgan('combined'));

About morgan

Morgan is an HTTP request logger middleware for Node.js that records incoming request details in a configurable log format. Named after Dexter Morgan, the library logs HTTP method, URL, status code, response time, content length, and other request metadata for each incoming request to your Express or Connect server. Morgan provides several predefined log formats including combined (Apache combined format), common (Apache common format), dev (concise colored output for development), short (shorter than default), and tiny (minimal output). Custom format strings use tokens like :method, :url, :status, :response-time, and :remote-addr to compose exactly the output format needed. Morgan supports custom token definitions for logging application-specific data, conditional logging based on request properties, and output to any writable stream (files, external logging services, or process.stdout). The dev format is popular during development for its colored status codes (green for success, red for server errors, yellow for client errors) and response time display. For production environments, Morgan is typically configured to output JSON format logs to a file or log aggregation service, complementing application-level loggers like Winston or Pino.

Quick Facts

Packagemorgan
CategoryUtility
Weekly Downloads5M+
LicenseMIT
Installnpm install morgan

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.