Skip to content

Instantly share code, notes, and snippets.

@meirkl
Created October 3, 2021 13:00
Show Gist options
  • Save meirkl/1af4c61bec4f2e2788cbb86c1861e415 to your computer and use it in GitHub Desktop.
Save meirkl/1af4c61bec4f2e2788cbb86c1861e415 to your computer and use it in GitHub Desktop.
const getActualRequestDurationInSeconds = start => {
const NS_PER_SEC = 1e9; // convert to nanoseconds
const diff = process.hrtime(start);
console.log( diff );
return (diff[0] * NS_PER_SEC + diff[1]) / NS_PER_SEC;
};
const requestDurationMiddleware = (req, res, next) => {
const start = process.hrtime();
res.on('finish', () => {
const durationInSeconds = getActualRequestDurationInSeconds(start);
console.log( durationInSeconds );
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment