expressjsHow do I configure logging in Express.js?
Express.js provides a simple and easy way to configure logging. Here is an example of how to configure logging in Express.js:
const express = require('express');
const logger = require('morgan');
const app = express();
// Configure logging
app.use(logger('dev'));
// Other Express.js settings
app.listen(3000);
This will enable logging with the morgan middleware. The logger middleware is configured with the dev
format, which is a predefined format to log requests in the Apache combined log format.
The logger
middleware takes a format string as its first argument. This string can have the following parts:
:method
- HTTP request method:url
- Requested URL:status
- HTTP response status code:response-time
- Time in milliseconds to process the request:date
- Date of the request:referrer
- Referrer URL:user-agent
- Browser user agent
For more information, see the Express.js documentation.
More of Expressjs
- How can I disable the X-Powered-By header in Express.js?
- How do I set up a YAML configuration file for a Node.js Express application?
- How do I find Express.js tutorials on YouTube?
- How can I use the x-forwarded-for header in Express.js?
- How do I use Express.js to handle x-www-form-urlencoded data?
- How can I set up X-Frame-Options in ExpressJS?
- How can I use an ExpressJS webhook to receive data from an external source?
- How can I use express-zip js to zip and download files?
- How can I use Express.js and Vite together for software development?
- How do I set the time zone in Express.js?
See more codes...