Don't reinvent, Install
Professional Monitoring
Section titled “Professional Monitoring”Why write your own traffic logger when you can hire a professional? Morgan is standard off-the-shelf middleware that logs requests automatically.
Fig 1: Automated Surveillance.
Why “Morgan”?
Section titled “Why “Morgan”?”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.
Installation
Section titled “Installation”npm install morganconst 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 - 23GET /missing 404 1.102 ms - 139 Professor Solo’s Directive:
Install this first. Always. Driving blind is for stuntmen, not engineers.
Extra Bits & Bytes
Section titled “Extra Bits & Bytes”Express Logging with Morgan - Demo Repo
NPM: Morgan