Here is an example of how to make event injection an accurate time measurement using express.js.
Add this in front of your routes:
app.all('*', function(req, res, next) { var start = process.hrtime(); // event triggers when express is done sending response res.on('finish', function() { var hrtime = process.hrtime(start); var elapsed = parseFloat(hrtime[0] + (hrtime[1] / 1000000).toFixed(3), 10); console.log(elapsed + 'ms'); }); next(); });
It will save the start time of each request and call finish after sending a response to the client.
Thanks for user419127, pointing to the "finish" event
source share