{"_id":"request-stats","_rev":"2934718","name":"request-stats","description":"Get stats on your Node.js HTTP server requests","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"watson","email":""}],"time":{"modified":"2023-03-29T06:05:21.000Z","created":"2014-06-09T15:50:53.669Z","3.0.0":"2017-05-01T13:13:54.663Z","2.0.1":"2016-12-15T22:04:17.676Z","2.0.0":"2016-11-24T10:09:36.838Z","1.0.1":"2014-08-12T15:16:51.605Z","1.0.0":"2014-08-10T09:12:21.147Z","0.3.2":"2014-07-11T13:10:24.978Z","0.3.1":"2014-06-20T12:03:17.138Z","0.3.0":"2014-06-16T08:10:11.847Z","0.2.2":"2014-06-10T10:03:25.392Z","0.2.1":"2014-06-10T08:20:47.607Z","0.2.0":"2014-06-10T08:12:54.068Z","0.1.0":"2014-06-09T15:50:53.669Z"},"users":{},"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"versions":{"3.0.0":{"name":"request-stats","version":"3.0.0","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"^3.0.1","once":"^1.4.0"},"devDependencies":{"https-pem":"^1.0.4","keep-alive-agent":"^0.0.1","standard":"^8.6.0","tape":"^4.6.3"},"engines":{"node":">=0.12"},"coordinates":[55.6811129,12.564524],"gitHead":"3ee1f52cb7777da424ff6c25f7e2b610664cc7be","_id":"request-stats@3.0.0","_shasum":"769155dc8974d78d4a1cb87bbf14eaab985afe25","_from":".","_npmVersion":"4.2.0","_nodeVersion":"7.8.0","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"769155dc8974d78d4a1cb87bbf14eaab985afe25","size":6436,"noattachment":false,"key":"/request-stats/-/request-stats-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-3.0.0.tgz"},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/request-stats-3.0.0.tgz_1493644433935_0.5643991858232766"},"directories":{},"publish_time":1493644434663,"_hasShrinkwrap":false,"_cnpm_publish_time":1493644434663,"_cnpmcore_publish_time":"2021-12-16T11:52:46.373Z"},"2.0.1":{"name":"request-stats","version":"2.0.1","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"^3.0.1","once":"^1.4.0"},"devDependencies":{"keep-alive-agent":"^0.0.1","standard":"^8.6.0","tape":"^4.6.3"},"coordinates":[55.7775770796403,12.59000686560671],"gitHead":"6494004d832a5b46a909bb8b6ac9b716d9975c17","_id":"request-stats@2.0.1","_shasum":"ed9a6381566af6bbd60fe2d5cfaf46f912b8b03e","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"ed9a6381566af6bbd60fe2d5cfaf46f912b8b03e","size":6318,"noattachment":false,"key":"/request-stats/-/request-stats-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-2.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/request-stats-2.0.1.tgz_1481839455827_0.01629171916283667"},"directories":{},"publish_time":1481839457676,"_hasShrinkwrap":false,"_cnpm_publish_time":1481839457676,"_cnpmcore_publish_time":"2021-12-16T11:52:46.598Z"},"2.0.0":{"name":"request-stats","version":"2.0.0","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"^3.0.1","once":"^1.4.0"},"devDependencies":{"keep-alive-agent":"^0.0.1","standard":"^8.6.0","tape":"^4.6.3"},"coordinates":[55.6810207,12.5644253],"gitHead":"8066391275f0911c30cd0f698cb002ec5e0aaac0","_id":"request-stats@2.0.0","_shasum":"585d22bd1d73023d4e2653ffd6c7e98e7aeab8ea","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"585d22bd1d73023d4e2653ffd6c7e98e7aeab8ea","size":6247,"noattachment":false,"key":"/request-stats/-/request-stats-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-2.0.0.tgz"},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/request-stats-2.0.0.tgz_1479982176254_0.07056340808048844"},"directories":{},"publish_time":1479982176838,"_hasShrinkwrap":false,"_cnpm_publish_time":1479982176838,"_cnpmcore_publish_time":"2021-12-16T11:52:46.804Z"},"1.0.1":{"name":"request-stats","version":"1.0.1","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x","once":"1.3.x"},"devDependencies":{"keep-alive-agent":"0.0.1","mocha":"1.21.x"},"gitHead":"fe4c10806c06caabe8777feeb08e5f9980b8060e","_id":"request-stats@1.0.1","_shasum":"7dbad4090caa5f5a0ea179ac80dbc584f74a7bf5","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"7dbad4090caa5f5a0ea179ac80dbc584f74a7bf5","size":6146,"noattachment":false,"key":"/request-stats/-/request-stats-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-1.0.1.tgz"},"directories":{},"publish_time":1407856611605,"_hasShrinkwrap":false,"_cnpm_publish_time":1407856611605,"_cnpmcore_publish_time":"2021-12-16T11:52:47.003Z"},"1.0.0":{"name":"request-stats","version":"1.0.0","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x","once":"1.3.x"},"devDependencies":{"mocha":"1.20.x"},"gitHead":"f0bb3d1742b4c5571dc1e4821d31402adfc479b1","_id":"request-stats@1.0.0","_shasum":"cc5fa81ff3f5ec340852a2db15ca21d0c1b896d6","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"cc5fa81ff3f5ec340852a2db15ca21d0c1b896d6","size":5724,"noattachment":false,"key":"/request-stats/-/request-stats-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-1.0.0.tgz"},"directories":{},"publish_time":1407661941147,"_hasShrinkwrap":false,"_cnpm_publish_time":1407661941147,"_cnpmcore_publish_time":"2021-12-16T11:52:47.258Z"},"0.3.2":{"name":"request-stats","version":"0.3.2","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x","once":"1.3.x"},"devDependencies":{"mocha":"1.20.x"},"_id":"request-stats@0.3.2","_shasum":"7dcd6c1406ff976e3fad61664710ac97117bf0db","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"7dcd6c1406ff976e3fad61664710ac97117bf0db","size":4375,"noattachment":false,"key":"/request-stats/-/request-stats-0.3.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-0.3.2.tgz"},"directories":{},"publish_time":1405084224978,"_hasShrinkwrap":false,"_cnpm_publish_time":1405084224978,"_cnpmcore_publish_time":"2021-12-16T11:52:47.538Z"},"0.3.1":{"name":"request-stats","version":"0.3.1","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x","once":"1.3.x"},"devDependencies":{"mocha":"1.20.x"},"_id":"request-stats@0.3.1","_shasum":"47411849bba2cc5e69c1720ad2d1221e112c9cdc","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"47411849bba2cc5e69c1720ad2d1221e112c9cdc","size":3870,"noattachment":false,"key":"/request-stats/-/request-stats-0.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-0.3.1.tgz"},"directories":{},"publish_time":1403265797138,"_hasShrinkwrap":false,"_cnpm_publish_time":1403265797138,"_cnpmcore_publish_time":"2021-12-16T11:52:47.731Z"},"0.3.0":{"name":"request-stats","version":"0.3.0","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x"},"devDependencies":{"mocha":"1.20.x"},"_id":"request-stats@0.3.0","_shasum":"f77e1e1f086b90af5d74ba3475ad04d02f15ac25","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"f77e1e1f086b90af5d74ba3475ad04d02f15ac25","size":3785,"noattachment":false,"key":"/request-stats/-/request-stats-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-0.3.0.tgz"},"directories":{},"publish_time":1402906211847,"_hasShrinkwrap":false,"_cnpm_publish_time":1402906211847,"_cnpmcore_publish_time":"2021-12-16T11:52:47.949Z"},"0.2.2":{"name":"request-stats","version":"0.2.2","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x"},"_id":"request-stats@0.2.2","_shasum":"882d5cda7420348451e28de60623204b327046fe","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"882d5cda7420348451e28de60623204b327046fe","size":3813,"noattachment":false,"key":"/request-stats/-/request-stats-0.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-0.2.2.tgz"},"directories":{},"publish_time":1402394605392,"_hasShrinkwrap":false,"_cnpm_publish_time":1402394605392,"_cnpmcore_publish_time":"2021-12-16T11:52:48.214Z"},"0.2.1":{"name":"request-stats","version":"0.2.1","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x"},"_id":"request-stats@0.2.1","_shasum":"97e6490f6ace4cd4d5ab95ec5aabf8c6f7ca416c","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"97e6490f6ace4cd4d5ab95ec5aabf8c6f7ca416c","size":3562,"noattachment":false,"key":"/request-stats/-/request-stats-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-0.2.1.tgz"},"directories":{},"publish_time":1402388447607,"_hasShrinkwrap":false,"_cnpm_publish_time":1402388447607,"_cnpmcore_publish_time":"2021-12-16T11:52:48.427Z"},"0.2.0":{"name":"request-stats","version":"0.2.0","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","dependencies":{"http-headers":"0.1.x"},"_id":"request-stats@0.2.0","_shasum":"a8e4b5db3e836b968c140f6853b9d4d9bbdd4a81","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"a8e4b5db3e836b968c140f6853b9d4d9bbdd4a81","size":3470,"noattachment":false,"key":"/request-stats/-/request-stats-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-0.2.0.tgz"},"directories":{},"publish_time":1402387974068,"_hasShrinkwrap":false,"_cnpm_publish_time":1402387974068,"_cnpmcore_publish_time":"2021-12-16T11:52:48.645Z"},"0.1.0":{"name":"request-stats","version":"0.1.0","description":"Get stats on your Node.js HTTP server requests","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git://github.com/watson/request-stats.git"},"keywords":["stats","statistics","http","https","middleware","connect","express","analytics"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk"},"license":"MIT","bugs":{"url":"https://github.com/watson/request-stats/issues"},"homepage":"https://github.com/watson/request-stats","_id":"request-stats@0.1.0","_shasum":"0e813f6f93270a8830758f2156965ea4d93be1af","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":""}],"dist":{"shasum":"0e813f6f93270a8830758f2156965ea4d93be1af","size":2999,"noattachment":false,"key":"/request-stats/-/request-stats-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/request-stats/download/request-stats-0.1.0.tgz"},"directories":{},"publish_time":1402329053669,"_hasShrinkwrap":false,"_cnpm_publish_time":1402329053669,"_cnpmcore_publish_time":"2021-12-16T11:52:48.848Z"}},"readme":"# request-stats\n\n[![Build status](https://travis-ci.org/watson/request-stats.svg?branch=master)](https://travis-ci.org/watson/request-stats)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)\n\nGet stats on your Node.js HTTP server requests.\n\nEmits two events:\n\n- `request` when ever a request starts: Passes a [Request object](#request-object) that can later be used to [query for the progress](#progress) of a long running request\n- `complete` when ever a request completes: Passes a [stats object](#oncomplete-callback) containing the overall stats for the entire HTTP request\n\n## Installation\n\n```\nnpm install request-stats --save\n```\n\n## Example usage\n\nGet stats for each completed HTTP request:\n\n```javascript\nvar requestStats = require('request-stats')\nvar server = http.createServer(...)\n\nrequestStats(server, function (stats) {\n  // this function will be called every time a request to the server completes\n  console.log(stats)\n})\n```\n\nGet periodic stats for long running requests:\n\n```javascript\nvar server = http.createServer(...)\n\nvar stats = requestStats(server)\n\nstats.on('request', function (req) {\n  // evey second, print stats\n  var interval = setInterval(function () {\n    var progress = req.progress()\n    console.log(progress)\n    if (progress.completed) clearInterval(interval)\n  }, 1000)\n})\n```\n\n## API\n\n### Constructor\n\n#### `requestStats(server[, callback])`\n\nAttach request-stats to a HTTP server.\n\nInitialize request-stats with an instance a HTTP server. Returns a\nStatsEmitter object. Optionally provide a callback which will be called\nfor each completed HTTP request with a stats object (see stats object\ndetails below).\n\nIf no callback is provided, you can later attach a listener on the\n\"complete\" event.\n\n#### `requestStats(req, res[, callback])`\n\nAttach request-stats to a single HTTP request.\n\nInitialize request-stats with an instance a HTTP request and response.\nReturns a StatsEmitter object. Optionally provide a callback which will\nbe called with a stats object when the HTTP request completes (see stats\nobject details below).\n\nIf no callback is provided, you can later attach a listener on the\n\"complete\" event.\n\n### StatsEmitter object\n\n#### `.on('complete', callback)`\n\nCalls the callback function with a stats object when a HTTP request\ncompletes:\n\n```javascript\n{\n  ok: true,           // `true` if the connection was closed correctly and `false` otherwise\n  time: 0,            // The milliseconds it took to serve the request\n  req: {\n    bytes: 0,         // Number of bytes sent by the client\n    headers: { ... }, // The headers sent by the client\n    method: 'POST',   // The HTTP method used by the client\n    path: '...',      // The path part of the request URL\n    ip: '...',        // The remote ip\n    raw: [Object]     // The original `http.IncomingMessage` object\n  },\n  res: {\n    bytes: 0,         // Number of bytes sent back to the client\n    headers: { ... }, // The headers sent back to the client\n    status: 200,      // The HTTP status code returned to the client\n    raw: [Object]     // The original `http.ServerResponse` object\n  }\n}\n```\n\n#### `.on('request', callback)`\n\nCalls the callback function with a special [Request\nobject](#request-object) when a HTTP request is made to the server.\n\n### Request object\n\nThe Request object should not be confused with the Node.js\n[http.IncomingMessage](http://nodejs.org/api/http.html#http_http_incomingmessage)\nobject. The request-stats Request object provides only a single\nbut powerfull function:\n\n#### `.progress()`\n\nReturns a progress object if called while a HTTP request is in progress.\nIf called multiple times, the returned progress object will contain the\ndelta of the previous call to `.progress()`.\n\n```javascript\n{\n  completed: false, // `false` if the request is still in progress\n  time: 0,          // The total time the reuqest have been in progress\n  timeDelta: 0,     // The time since previous call to .progress()\n  req: {\n    bytes: 0,       // Total bytes received\n    bytesDelta: 0,  // Bytes received since previous call to .progress()\n    speed: 0,       // Bytes per second calculated since previous call to .progress()\n    bytesLeft: 0,   // If the request contains a Content-Size header\n    timeLeft: 0     // If the request contains a Content-Size header\n  },\n  res: {\n    bytes: 0,       // Total bytes send back to the client\n    bytesDelta: 0,  // Bytes sent back to the client since previous call to .progress()\n    speed: 0        // Bytes per second calculated since previous call to .progress()\n  }\n}\n```\n\n## Acknowledgement\n\nThanks to [mafintosh](https://github.com/mafintosh) for coming up with\nthe initial concept and pointing me in the right direction.\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/watson/request-stats","bugs":{"url":"https://github.com/watson/request-stats/issues"},"license":"MIT"}