I want to get current time in nanoseconds in node.
I tried the following function, but it’s not working.
Is there any other way to do it?
function getNanoSecTime() {
var hrTime = process.hrtime();
return hrTime[0] * 1000000000 + hrTime[1];
}
3
Answers
To get the current time in nanoseconds as a
bigint
, you can use the following built-int function:See the documentation
Node has built in functionality to get time with nanoseconds. here is the examples of get nanoseconds
Node.js 10.7.0+ – Use
Rest Versions – Use
Install with npm:
$ npm install --save nanoseconds
then :