Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
The nano-time npm package provides high-resolution time stamps based on the Unix epoch. It allows for the generation of nanosecond precision time stamps, which are particularly useful in performance measurement, logging, and other scenarios where more granularity than milliseconds is required.
Getting the current time in nanoseconds
This feature allows you to get the current time in nanoseconds since the Unix epoch. It's useful for high-precision time measurements.
const nanoTime = require('nano-time');
let currentTime = nanoTime.now();
Converting a Date object to nanoseconds
This feature converts a JavaScript Date object to a nanosecond precision timestamp. It's useful for when you need to work with both standard JavaScript dates and high-resolution timestamps.
const nanoTime = require('nano-time');
let date = new Date();
let nanoSeconds = nanoTime.fromDate(date);
The hrtime package offers high-resolution time measurements similar to nano-time, but it mimics the process.hrtime() method available in Node.js. Unlike nano-time, hrtime provides time in seconds and nanoseconds as a tuple, which can be more convenient for certain applications.
This package provides a way to get high-resolution timestamps in milliseconds, similar to window.performance.now() in the browser. While it offers high precision, it's limited to millisecond resolution, making nano-time more suitable for applications requiring nanosecond precision.
Gets the current time in nanoseconds or microseconds.
In node.js you can get high resolution time with process.hrtime()
, but it is from an unknown relative time, not epoch. So this library helps that by calculating the difference and adding it to the current time.
Since javascript can't hold a nanosecond as an INT safely (Number.MAX_SAFE_INTEGER), we return a string instead.
const now = require('nano-time');
now(); // '1476742925219947761' (returns a string)
now.micro(); // '1476742921398373'
now.microseconds(); // alias for now.micro();
FAQs
Current Time in Nanoseconds
The npm package nano-time receives a total of 624,224 weekly downloads. As such, nano-time popularity was classified as popular.
We found that nano-time demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.