Skip to content

Don't reinvent, Install

Why write your own traffic logger when you can hire a professional? Morgan is standard off-the-shelf middleware that logs requests automatically.

A high-tech surveillance drone camera with 'MORGAN' stenciled on the side, projecting a holographic log of HTTP requests.

Fig 1: Automated Surveillance.

Trivia: The package is named after Dexter Morgan, the famous blood-spatter analyst (and serial killer) from the TV show Dexter. It analyzes the “splatter” of your HTTP requests.

Terminal window
npm install morgan
const express = require('express');
const morgan = require('morgan');
const app = express();
// 'dev' is the log format (concise and colored)
app.use(morgan('dev'));

Now your terminal looks like a real hacker dashboard. It tells you the Method, the URL, the Status Code, and how long the request took (in ms).

GET /things 200 4.205 ms - 23
GET /missing 404 1.102 ms - 139
Professor Solo’s Directive:

Install this first. Always. Driving blind is for stuntmen, not engineers.


Express Logging with Morgan - Demo Repo

NPM: Morgan

⏭ Static Assets

Sometimes users just need to grab a map or a pic without a security check.