Categories
JavaScript Answers

How to get a microtime in Node.js?

Spread the love

To get a microtime in Node.js, we use the performance-now module.

For instance, we write

const loadTimeInMS = Date.now();
const performanceNow = require("performance-now");
console.log((loadTimeInMS + performanceNow()) * 1000);

to call performanceNow to get the current timestamp in milliseconds.

We multiply it by 1000 to get the value in microseconds.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *