nodejs request library, get the response time

前端 未结 3 1870
傲寒
傲寒 2021-02-13 13:41

Using the nodejs request library: https://github.com/mikeal/request

var request = require(\'request\');
request(\'http://example.com\', function (er         


        
3条回答
  •  猫巷女王i
    2021-02-13 14:02

    Something like

    var timedReq = function(url, next) {
      var start = new Date();
      request(url, function(err, res, body) {
        res.responseTime = new Date() - start;
        next(err, res, body);
      });
    };
    

    will do it for you. This seems small enough that it's probably easier than finding a new library.

提交回复
热议问题