Registry / web-framework / lum_request-stats

lum_request-stats

JSON →
library3.2.0jsnpmunverified

request-stats is a Node.js library that collects HTTP request statistics for Node.js HTTP servers. It emits events for request start and completion, providing metrics such as bytes transferred, duration, headers, method, path, IP, and status code. It also offers a progress() method for long-running requests. Version 3.2.0 is the latest stable release; the project appears to be in maintenance mode with no recent updates (last commit several years ago). Key differentiators: simple API, event-based, supports both per-request and per-server stats, and works with plain HTTP servers, Express, and other frameworks.

npm install lum_request-stats
INSTALL
IMPORT
SIG · LUM_REQUEST-STATS
L
lum_request-stats
web-frameworkjavascriptv3.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

requestStats (default)
import requestStats from 'request-stats'
const requestStats = require('request-stats')
The package is CommonJS only, so require() is correct; the ESM import shown is a polyfill for environments that support it.
requestStats (as function)
const requestStats = require('request-stats')
import { requestStats } from 'request-stats'
The package exports a single function as default. Named import will fail.
StatsEmitter type (TypeScript)
import requestStats from 'request-stats'; const stats: requestStats.StatsEmitter = requestStats(server)
import { StatsEmitter } from 'request-stats'
The package does not ship TypeScript definitions; you may need to install @types/request-stats or define your own.

Attaches request-stats to an HTTP server and logs stats for each completed request.

const http = require('http'); const requestStats = require('request-stats'); const server = http.createServer((req, res) => { res.statusCode = 200; res.end('Hello World'); }); requestStats(server, (stats) => { console.log(`Request completed in ${stats.time}ms`); console.log(`Status: ${stats.res.status}`); console.log(`Bytes sent: ${stats.res.bytes}`); }); server.listen(3000);
Debug
Known issues
gotchaThe .progress() method returns delta values on subsequent calls, not cumulative totals.
fix
If you need cumulative values, accumulate manually or call .progress() only once per interval.
affects: >=1.0
gotchaThe 'request' event emits a Request object, not Node.js's http.IncomingMessage.
fix
Access the raw request via the 'raw' property on the Request object.
affects: >=1.0
breakingVersion 2.0 changed the stats object structure: removed 'req.query' and 'req.body'.
fix
Upgrade to v3 or manually parse query/body from the raw request.
affects: =2.0.0
deprecatedThe package has not been updated for Node.js >=14. Some internal HTTP APIs may behave differently.
fix
Test with your Node version; consider using alternatives like 'express-http-context' or custom middleware.
affects: >=3.0.0
gotchaWhen attaching to a single request with requestStats(req, res), the callback is invoked once; attempting to attach again will overwrite listeners.
fix
Use the server-wide attachment for multiple requests.
affects: >=1.0
Errors
Common errors & fixes
TypeError: requestStats is not a function
Using named import instead of default import with CommonJS.
fix
Use const requestStats = require('request-stats');
Cannot read properties of undefined (reading 'on')
Calling requestStats() without a server or req/res object.
fix
Provide either a server object or a request/response pair as the first argument.
stats.req.headers is undefined
Attempting to access headers before the 'complete' event fires.
fix
Access stats object only inside the callback or 'complete' event listener.
Upgrade
Version history
3.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
lum_request-stats — npm install lum_request-stats · libregistry