Naughty Pinching Mannequins
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

server-timing

2.1.0 • Public • Published

server-timing

Build Status Coverage Status

This module adds Server-Timing to response headers. Example is here and open chrome devtool network tab.

You can use this as a express module / basic http function.

Install

$ npm install server-timing -S

Usage

const express = require('express');
const serverTiming = require('server-timing');
 
const app = express();
app.use(serverTiming());
 
app.use((req, res, next) => {
  res.startTime('file', 'File IO metric');
  setTimeout(() => {
    res.endTime('file');
  }, 100);
  next();
});
app.use((req, res, next) => {
  // All timings should be in milliseconds (s). See issue #9 (https://github.com/yosuke-furukawa/server-timing/issues/9).
  res.setMetric('db', 100.0, 'Database metric');
  res.setMetric('api', 200.0, 'HTTP/API metric');
  res.setMetric('cache', 300.0, 'cache metric');
  next();
});
app.use((req, res, next) => {
  res.send('hello');
});

API

constructor(options)

  • options.total: boolean, default true
  • options.enabled: boolean, default true

Result

image

install

npm i server-timing

Downloadsweekly downloads

684

version

2.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability