From the course: Node.js: Debugging and Performance Tuning

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Request logging with Morgan

Request logging with Morgan

From the course: Node.js: Debugging and Performance Tuning

Start my 1-month free trial

Request logging with Morgan

- [Instructor] It's good to avoid reinventing the wheel, and we made a pretty square one a couple of videos ago when we used the console to log requests. As we saw, it worked, but it wasn't optimal. Is there a better solution? Yes, and it's called morgan. Morgan is a no-JS HTTP request logger middleware which supports servers including Express. When logging, morgan includes a number of details about the HTTP method, path requested, and content length. Morgan logs once the request is sent so it can include the HTTP status code and response time, which is really useful for debugging and finding slow performance. Optionally, morgan can also include the referrer and user agent strain. Morgan can be used with most loggers, including Winston. Morgan provides some very convenient logging format defaults including the standard Apache combined log output. It also provides a system of token replacements so you can easily create your own, or customize it. We're going to replace our console…

Contents