{"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":"w@tson.dk"}],"dist":{"shasum":"585d22bd1d73023d4e2653ffd6c7e98e7aeab8ea","tarball":"http://registry-npm.ywwl.com/request-stats/download/request-stats-2.0.0.tgz","integrity":"sha512-Jg38478KxIGQ/b3wKxBMWzRivt9DV9iHhBmiCgamxCPcZy8w4j568JZawU3whKU2AQlQ4UgyfehCom+NXwaU4A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjFCBIgHkNmTqXb12zAZ0wl+uQxNrELAUlb2Tei1rA7AIhAL5KRCaTEAGD1LDh6E3JC5jGlQ5XQwL8snDgEk8MxJ+4"}],"size":6247,"noattachment":false,"key":"/request-stats/-/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":{},"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","publish_time":1479982176838,"_cnpm_publish_time":1479982176838,"dist-tags":{"latest":"3.0.0"}}