Server-Timing
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 = ;var timing = ; var queryTimer = timing; // ... do something work-intensive var timeInMS = queryTimer;// or; var timeInMS = timing.stopTimer("Database Query"); // you can also add metrics without the timer function// the time value is always in milliseconds!timing // If an operation you are timing fails before the// timer can be stopped, you can clear that timertry timing; throw "The operation failed!"; timing; catch e timing; // ... use the header string within your server framework or whateverres;return res; // 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!