{"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":"w@tson.dk"}],"dist":{"shasum":"882d5cda7420348451e28de60623204b327046fe","tarball":"http://registry-npm.ywwl.com/request-stats/download/request-stats-0.2.2.tgz","integrity":"sha512-optrEWge7Br3+nHFc6lJCJdz+iyRTf00T0bJG9+V+kI3SfaF4vjMjW8FUmJIogLSkmryLHqjs0Om5pPDMHv8XA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD9yCbkJ+soCWJvYToDN/Ct2A2ntTyVrEjNgZI9l3pcpwIgUQRWDFxMBUjngWMkz8jRoOzkF/yrTL9F0vebsvnk2Dk="}],"size":3813,"noattachment":false,"key":"/request-stats/-/request-stats-0.2.2.tgz"},"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":1402394605392,"_cnpm_publish_time":1402394605392,"dist-tags":{"latest":"3.0.0"}}