skip to Main Content

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


  1. To get the current time in nanoseconds as a bigint, you can use the following built-int function:

    process.hrtime.bigint();
    

    See the documentation

    Login or Signup to reply.
  2. Node has built in functionality to get time with nanoseconds. here is the examples of get nanoseconds

    Node.js 10.7.0+ – Use

    process.hrtime.bigint()
    

    Rest Versions – Use

    process.hrtime()
    
    Login or Signup to reply.
  3. Install with npm:

    $ npm install --save nanoseconds

    then :

    const nano = require('nanoseconds');
    console.log(nano(process.hrtime()));
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search