Morgan is an HTTP request logger middleware for Node.js that integrates with Express applications to record incoming requests and outgoing responses.
Morgan solves the problem of tracking HTTP traffic through your application by providing a middleware layer that logs request and response details. It works by intercepting requests as they flow through Express, capturing information like method, URL, status code, and response time, then writing formatted log entries to a specified output stream. The tool offers both predefined log formats modeled after Apache standards and the ability to define custom formats through either token-based strings or custom functions that receive the full request and response objects.
Developers should choose Morgan if they need straightforward HTTP request logging in an Express application without additional dependencies or complexity. It suits projects ranging from development environments where colored, concise output aids debugging to production systems requiring structured logging. The tool provides several predefined formats including combined and common Apache formats, a development format with color-coded status indicators, and minimal formats for compact output. Custom token definitions allow extending the logger with application-specific data. The immediate option enables logging even if the server crashes, though response data becomes unavailable. The skip function lets you conditionally suppress logging for certain requests, and the stream option allows directing output to files, log aggregation services, or structured logging systems that accept objects.
The project maintains steady engagement with regular issue responses and pull request reviews. Development activity shows consistent attention to bug reports and feature requests from the community. The maintainers demonstrate responsiveness to compatibility concerns and edge cases raised by users. Updates are released to address reported issues and maintain compatibility with evolving Node.js and Express versions.