http-request-timings

1.0.0 • Public • Published

http-request-timings

Build Status Coverage Status Dependency Status devDependency Status js-standard-style

NPM

This module monkey-patches the http.request method – which is used internally by http.get, https.request, https.get and therefor any library like request – to record timings.

Note: The core https module isn't patched on node <=0.10. This will be addressed in a future version.

npm install -S http-request-timings
var http = require('http')
 
var timings = require('http-request-timings')
 
// monkey-patch http.request
timings.start()
 
timings.on('timing', function (timing, options, res) {
  timing.start // Date
  timing.firstByte // Date
  timing.end // Date
 
  timing.timeToFirstByte // duration in ms
  timing.timeToEnd // duration in ms
 
  // options passed to http.request
  // if it was originally a string then it's `url.parse`d
  options
 
  // the response
  res
})
 
http.get('http://example.com/', function (res) {
  // …
  res.on('data', doStuff)
 
  // go back to default http.request
  timings.stop()
})

Package Sidebar

Install

npm i http-request-timings

Weekly Downloads

15

Version

1.0.0

License

MIT

Last publish

Collaborators

  • boennemann