index.js
function responseTime (options) {
  var opts = options || {}

  if (typeof options === 'number') {
    // back-compat single number argument
    deprecate('number argument: use {digits: ' + JSON.stringify(options) + '} instead')
    opts = { digits: options }
  }

  // get the function to invoke
  var fn = typeof opts !== 'function'
    ? createSetHeader(opts)
    : opts

  return function responseTime (req, res, next) {
    var startAt = process.hrtime()

    onHeaders(res, function onHeaders () {
      var diff = process.hrtime(startAt)
      var time = diff[0] * 1e3 + diff[1] * 1e-6

      fn(req, res, time)
    })

    next()
  }
}
function responseTime (options) {
  var opts = options || {}

  if (typeof options === 'number') {
    // back-compat single number argument
    deprecate('number argument: use {digits: ' + JSON.stringify(options) + '} instead')
    opts = { digits: options }
  }

  // get the function to invoke
  var fn = typeof opts !== 'function'
    ? createSetHeader(opts)
    : opts

  return function responseTime (req, res, next) {
    var startAt = process.hrtime()

    onHeaders(res, function onHeaders () {
      var diff = process.hrtime(startAt)
      var time = diff[0] * 1e3 + diff[1] * 1e-6

      fn(req, res, time)
    })

    next()
  }
}
function responseTime ( options ) { var opts = options || { } if ( typeof options === 'number' ) { // back-compat single number argument deprecate ( 'number argument: use {digits: ' + JSON . stringify ( options ) + '} instead' ) opts = { digits : options } } // get the function to invoke var fn = typeof opts !== 'function' ? createSetHeader ( opts ) : opts return function responseTime ( req , res , next ) { var startAt = process . hrtime ( ) onHeaders ( res , function onHeaders ( ) { var diff = process . hrtime ( startAt ) var time = diff [ 0 ] * 1e3 + diff [ 1 ] * 1e-6 fn ( req , res , time ) } ) next ( ) } }
Create a middleware to add a `X-Response-Time` header displaying
the response duration in milliseconds.

@param {object|function} [options]
@param {number} [options.digits=3]
@param {string} [options.header=X-Response-Time]
@param {boolean} [options.suffix=true]
@return {function}
@public
Create a middleware to add a X - Response - Time header displaying the response duration in milliseconds .