X-Response-Time header for node.js
$ npm install response-time
var responseTime = require('response-time')
Returns middleware that adds a X-Response-Time
header to responses.
digits
- the fixed number of digits to include. (default:3
)
var express = require('express')
var responseTime = require('response-time')
var app = express()
app.use(responseTime())
app.get('/', function (req, res) {
res.send('hello, world!')
})
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!')
})
})