1.5.0 • Published 6 years ago

servertiming v1.5.0

Weekly downloads
22
License
MIT
Repository
github
Last release
6 years ago

Server-Timing Build Status npm version

Generate Server-Timing headers interactively by setting timers in NodeJS

Inpired by:

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!

1.5.0

6 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago