Skip to content

๐Ÿ“Š Generate Server-Timing headers interactively in NodeJS

License

Notifications You must be signed in to change notification settings

thomasbrueggemann/node-servertiming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

43 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Server-Timing Build Status npm version

Generate Server-Timing headers interactively by setting timers in NodeJS

Inpired by:

๐Ÿ“Š View your server's metrics in @ChromeDevTools via Server Timing headers. Big thanks to longtime Firebug developer @sroussey for the patch! pic.twitter.com/OjDDIv0lLR

โ€” Paul Irish (@paul_irish) February 7, 2017

Installation

npm install servertiming --save

Usage

var ServerTiming = require("servertiming");
var timing = new ServerTiming();

var queryTimer = timing.startTimer("Database Query");

// ... do something work-intensive

var timeInMS = queryTimer.stop();
// or; var timeInMS = timing.stopTimer("Database Query");

// you can also add metrics without the timer function
// the time value is always in milliseconds!
timing.addMetric("Image Processing", 12847)

// If an operation you are timing fails before the
// timer can be stopped, you can clear that timer
try {
	timing.startTimer("Failed Operation");
	throw new Error("The operation failed!");
	timing.stopTimer("Failed Operation");
} catch (e) {
	timing.clearTimer("Failed Operation");
}

// ... use the header string within your server framework or whatever
res.setHeader("Server-Timing", timing.generateHeader());
return res.send({whatever: "you want"});

// this will output:
// database-query; dur=122; desc="Database Query",image-processing; dur=12847; desc="Image Processing"

See the /example folder for a detailed express.js example!

About

๐Ÿ“Š Generate Server-Timing headers interactively in NodeJS

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •