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 = ;const router = ; router; moduleexports = router;
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 = ;const simpleTiming = ;const router = ; { ;} router;
Test
npm test