Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

thomasbrueggemann/node-servertiming

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

43 Commits
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

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.