README
http-request-timings
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()
})