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 install morgan
yarn add morgan
pnpm add morgan
Import
import morgan from 'morgan';
Quick Example
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
| Package | morgan |
| Category | Utility |
| Weekly Downloads | 5M+ |
| License | MIT |
| Install | npm install morgan |
Related Packages
Winston is the most popular logging library for Node.js, designed to be a simple and universal loggi…
Pino is an extremely fast Node.js logger that outputs newline-delimited JSON (NDJSON) with minimal o…
Express is the most widely used web application framework for Node.js, providing a minimal and flexi…
debug is a tiny JavaScript debugging utility modeled after Node.js core's debugging technique, provi…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.