Skip to content

Latest commit

 

History

History
81 lines (58 loc) · 1.95 KB

README.md

File metadata and controls

81 lines (58 loc) · 1.95 KB

response-time

NPM Version NPM Downloads Build Status Test Coverage Gratipay

X-Response-Time header for node.js

Installation

$ npm install response-time

API

var responseTime = require('response-time')

responseTime(digits)

Returns middleware that adds a X-Response-Time header to responses.

  • digits - the fixed number of digits to include. (default: 3)

Examples

express/connect

var express = require('express')
var responseTime = require('response-time')

var app = express()

app.use(responseTime())

app.get('/', function (req, res) {
  res.send('hello, world!')
})

vanilla http server

var finalhandler = require('finalhandler')
var http = require('http')
var responseTime = require('response-time')

// create "middleware"
var _responseTime = responseTime()

http.createServer(function (req, res) {
  var done = finalhandler(req, res)
  _responseTime(req, res, function (err) {
    if (err) return done(err)

    // respond to request
    res.setHeader('content-type', 'text/plain')
    res.end('hello, world!')
  })
})

License

MIT