Skip to content

RafLeszczynski/response-time

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

X-Response-Time header for node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published