dox-foundation-demo node_modules/express/node_modules/connect/lib/middleware/responseTime.js

exports

method
module.exports()
  • @return: {Function}

Description

Reponse time:

Adds the X-Response-Time header displaying the response
duration in milliseconds.

Source

module.exports = function responseTime(){
  return function(req, res, next){
    var start = new Date;

    if (res._responseTime) return next();
    res._responseTime = true;

    res.on('header', function(){
      var duration = new Date - start;
      res.setHeader('X-Response-Time', duration + 'ms');
    });

    next();
  };
};