Created
October 3, 2021 13:00
-
-
Save meirkl/1af4c61bec4f2e2788cbb86c1861e415 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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