1.0.0 • Published 7 months ago

@pirxpilot/server-timings v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

NPM version Build Status Dependency Status

@pirxpilot/server-timings

This is a modernized fork of server-timings

Usage

Load the middleware as early as possible to record the request timing:

const express = require('express');
const app = express();
const timings = require('server-timings');

app.use(timings);
app.use(require('./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.45

To include additional timings the middleware exposes two methods on the res.locals.timings property:

  • start(label[, description]) - record the start time
  • end(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:

app.use(timings);
app.use(timings.start('routing'));
app.use(require('./routes'));
app.use(timings.end('routing'));
1.0.0

7 months ago