Using the nodejs request
library: https://github.com/mikeal/request
var request = require(\'request\');
request(\'http://example.com\', function (er
Instead of using Date() you could also use process.hrtime. I have a library specifically for these kind of cases that uses hrtime. The library name is exectimer.
You could use it like this:
var timedReq = function(url, next) {
var tick = new t.Tick("responseTime");
tick.start();
request(url, function(err, res, body) {
tick.stop();
next(err, res, body);
});
};
// when ready check the results with this:
var responseTime = t.timers.responseTime;
console.log(responseTime.min()); // minimal response time
console.log(responseTime.max()); // minimal response time
console.log(responseTime.mean()); // mean response time
console.log(responseTime.median()); // median response time