Morgan HTTP Logger

1.10.1 · active · verified Sat Apr 18

Morgan is an HTTP request logger middleware for Node.js, often used with the Express framework. It allows developers to log request details such as method, URL, status, and response time in various predefined or custom formats. The current stable version is 1.10.1. Releases occur infrequently, with the latest update focusing on minor fixes and dependency updates, indicating a mature and stable library.

Common errors

Warnings

Install

Quickstart

This quickstart sets up a basic Express.js application and integrates Morgan middleware using the 'dev' format for logging HTTP requests. It demonstrates how Morgan logs incoming requests and their responses, including status codes and response times.

const express = require('express');
const morgan = require('morgan');
const app = express();
const port = process.env.PORT ?? 3000;

// Use 'dev' format for concise colored output during development
app.use(morgan('dev'));

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.get('/error', (req, res) => {
  res.status(500).send('Something broke!');
});

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

view raw JSON →