@pirxpilot/server-timings
v2.0.0
Published
Adds `Server-Timings` header
Maintainers
Readme
@pirxpilot/server-timings
This is a modernized fork of server-timings
Usage
Load the middleware as early as possible to record the request timing:
import express from 'express';
import timings from 'server-timings';
import routes from './routes.js';
const app = express();
app.use(timings);
app.use(routes);This will automatically add a Server-Timing header shown in milliseconds.
$ curl https://jsonbin.org/remy/urls -I
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server-Timing: total; dur=72.45To include additional timings the middleware exposes two methods on the res.locals.timings property:
start(label[, description])- record the start timeend(label)- end the record time - if this isn't called, it will be called when the request is finished
Start/end as middleware
As well as being exposed in res.locals.timings you can also call start and end as middleware:
import timings from 'server-timings';
import routes from './routes.js';
app.use(timings);
app.use(timings.start('routing'));
app.use(routes);
app.use(timings.end('routing'));