node.js - nodejs request library, get the response time -


using nodejs request library: https://github.com/mikeal/request

var request = require('request'); request('http://example.com', function (error, response, body) {    ... }) 

is possible response time on callback? doc mentions response.statuscode. looking @ library source code see undocumented response.headers , response.href, don't see responsetime or similar.

or, there alternative library request provides response time?

ps: know this, that's not solution, making many async requests , cannot control when each request started.

var request = require('request'); var start = new date(); request('http://example.com', function (error, response, body) {    ...    var responsetime = new date() - start; }) 

the request library can timing (docs):

request.get({   url : 'http://example.com',   time : true },function(err, response){   console.log('request time in ms', response.elapsedtime); }); 

as question implies, issues approach of starting timer, calling request stopping timer in callback:

var start = new date(); request.get('http://example.com', function(err, response){   // not   console.log('request time plus 5 seconds', new date() - start); }); require('sleep').sleep(5); // time-consuming synchronous action 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -