A minimal Express app demonstrating request logging using the morgan middleware.
Morgan logs every incoming request:
- HTTP method
- URL
- status code
- response time
Perfect for development and debugging.
- Node.js
- npm
Check:
node -v
npm -vnpm installnpm startOpen these routes and watch your terminal:
http://localhost:3000/http://localhost:3000/things
You’ll see logs like:
GET /things 200 3.123 ms - 52npm run watchStop with:
Ctrl + C
app.use(morgan("dev"));- Morgan is just middleware
- it must be registered before your routes
'dev'format is ideal for local development
.
├── app.js
├── package.json
└── README.mdNode2Know-LEARN-1.0