request-stats is a Node.js library designed to collect detailed statistics on HTTP server requests and responses. It tracks metrics such as total request duration, bytes sent by the client, bytes sent back to the client, request headers, HTTP method, request path, remote IP address, and the HTTP status code of the response. The current stable version, as of the provided information, is 3.0.0. The package emits two primary events: `request`, which fires when a request begins and provides a special `Request` object for monitoring progress, and `complete`, which fires when a request concludes and delivers a comprehensive `stats` object. A key differentiator of `request-stats` is its unique `.progress()` method available on the `Request` object, allowing developers to periodically query for real-time statistics of long-running requests, including incremental deltas since the last query. This capability goes beyond simple request completion tracking, offering deeper insights into in-flight request performance. The library supports attaching to an entire Node.js `http.Server` instance or to individual `http.IncomingMessage` and `http.ServerResponse` pairs.
npm install request-statsVerified import paths — ran on the pinned version, not inferred.
This example initializes `request-stats` on a basic Node.js HTTP server, logging detailed statistics for each completed request, including method, path, status, duration, byte counts, and connection status.
Ensure compatibility by testing `request-stats` thoroughly with your specific Node.js runtime version, especially if using newer Node.js features or modules.
Use the default import syntax for ESM: `import requestStats from 'request-stats'` or stick to CommonJS `require('request-stats')`.Call `req.progress()` at reasonable intervals (e.g., every second or few seconds) to monitor long-running requests without excessive performance impact. Use it judiciously based on your application's profiling.
Always check `stats.ok` in your `complete` event listener to properly categorize and handle requests that did not finish gracefully, distinguishing them from successfully completed ones.
Change your import statement to `import requestStats from 'request-stats'` for ESM, or use `const requestStats = require('request-stats')` for CommonJS.Run `npm install request-stats` or `yarn add request-stats` in your project directory. Verify your `NODE_PATH` or module resolution configuration if the issue persists after installation.
No dependency data recorded yet.