New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-simple-timing

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-simple-timing

Express middleware that sends Server-Timing stats for routes

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

express-simple-timing

Express middleware that sets Server Timing API headers and optionally sends timers to stats systems.

express-simple-timing returns a middleware function that can be used with an express server. It sends Server-Timing headers to the client to allow inspection of route timings. It can also send stats to your stats system by using a callback passed into the constructor.

A default key of total is created based on the total time to deliver the entire route.

Installation

npm install --save express-simple-timing

Example Usage

const simpleTiming = require('express-simple-timing');
const router = require('express').Router();

router.use(simpleTiming());

module.exports = router.put('/mypath', function(req, res) {
  res.json({
    message: 'my response'
  });
});

This will add a total value by default, such as:

server-timing: total;dur=4.043

Custom metrics

By using the serverTimingStart and serverTimingEnd methods you can send ad hoc metrics for your app:

res.serverTimingStart('woof');
barkLikeADog();
res.serverTimingEnd('woof');

This will then add an additional timing header:

server-timing: woof;dur=2.43

Stats Callback

To use the timing metrics in your own stats system, you can pass a callback which receives req, key and value every time a server-timing header is added.

const myStats = require('my-stats-system');
const simpleTiming = require('express-simple-timing');
const router = require('express').Router();

function myStatsHook(req, key, value) {
  myStats(req.url, key, value);
}

router.use(simpleTiming(myStatsHook));

Test

npm test

FAQs

Package last updated on 16 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc