eolas/neuron/bcf3fe86-88d2-4155-a9c4-3102e956f8f8/Morgan.md

28 lines
599 B
Markdown
Raw Normal View History

2024-10-19 11:00:03 +01:00
---
tags:
- node-js
- middleware
---
# Morgan
Morgan is middleware that is used to log HTTP requests to the Express instance.
```js
app.use(morgan("dev"));
```
With Morgan in place, every time we run a request it will be logged on the
console that is running our Node application, e.g:
```plain
GET /api/courses 200 95 - 1.774 ms
```
This uses the `tiny` default which logs the bare minimum giving us: request
type; endpoint; response code; and time to execute. But there are more verbose
settings.
It defaults to logging on the console but can also be configured to write to a
log file.