Registry / http-networking / ntp-packet-parser

ntp-packet-parser

JSON →
library0.5.0jsnpmunverified

This library provides a utility for parsing Network Time Protocol (NTP) UDP response packets into a structured JavaScript object. It adheres to RFC 5905, focusing solely on data extraction rather than time validation or calculations. The current stable version is 0.5.0, with a release cadence that generally follows Node.js LTS cycles, providing support for Node.js 18, 20, and 22. It is actively maintained with recent updates addressing Node.js compatibility and dependency bumps. Its primary differentiator among NTP parsing utilities is its singular focus on robust packet parsing, providing a structured representation of all standard NTP fields without imposing further logic, leaving time synchronization calculations and network interactions to consumer libraries. This strict separation of concerns makes it a reliable low-level building block for higher-level NTP client implementations.

npm install ntp-packet-parser
INSTALL
IMPORT
SIG · NTP-PACKET-PARSER
N
ntp-packet-parser
http-networkingjavascriptv0.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NtpPacketParser
import { NtpPacketParser } from 'ntp-packet-parser';
import NtpPacketParser from 'ntp-packet-parser';
The main parser class is a named export. Attempting a default import will result in 'NtpPacketParser is not a function'.
NtpPacket
import type { NtpPacket } from 'ntp-packet-parser';
import { NtpPacket } from 'ntp-packet-parser';
NtpPacket is a TypeScript interface for the parsed result. Use `import type` for clarity and bundler optimization.
CommonJS require
const { NtpPacketParser } = require('ntp-packet-parser');
const NtpPacketParser = require('ntp-packet-parser');
For CommonJS, NtpPacketParser is a named property of the module export, not the default export itself. While deprecated in favor of ESM, this pattern is still supported.

This quickstart demonstrates how to import the `NtpPacketParser` and its `NtpPacket` type, then parse a mock raw UDP buffer representing an NTP response into a structured object, accessing its key properties.

import { NtpPacketParser, NtpPacket } from 'ntp-packet-parser'; // A real NTP packet is 48 bytes. This is a mock buffer for demonstration. // In a real application, this buffer would be received from a UDP socket. const mockUdpPacket = Buffer.from([ 0x24, 0x01, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x0a, 0x3d, 0x76, 0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6 ]); try { const result: NtpPacket = NtpPacketParser.parse(mockUdpPacket); console.log('NTP Packet Parsed:'); console.log(` Leap Indicator: ${result.leapIndicator}`); console.log(` Version: ${result.version}`); console.log(` Mode: ${result.mode}`); console.log(` Stratum: ${result.stratum}`); console.log(` Reference ID: ${result.referenceId}`); console.log(` Transmit Timestamp: ${result.transmitTimestamp.toISOString()}`); // Example of calculating relative time for a Date property const unixEpoch = new Date('Jan 01 1900 GMT').getTime(); const rootDelayInMilliseconds = result.rootDelay.getTime() - unixEpoch; console.log(` Root Delay in milliseconds (relative to 1900): ${rootDelayInMilliseconds}`); } catch (error) { console.error('Error parsing NTP packet:', error); }
Debug
Known issues
breakingVersion 0.5.0 dropped support for Node.js versions prior to 18. Ensure your Node.js environment is at least 18.x, 20.x, or 22.x.
fix
Upgrade your Node.js runtime to version 18 or newer.
affects: >=0.5.0
breakingVersion 0.3.0 dropped support for Node.js v12. Users on older Node.js runtimes should either upgrade or stick to an earlier version of `ntp-packet-parser`.
fix
Upgrade your Node.js runtime to version 14 or newer for versions 0.3.x-0.4.x, or 18+ for 0.5.0+.
affects: >=0.3.0
gotchaNPM release 0.4.0 was broken due to an incorrect tag. Using version 0.4.0 may lead to installation or runtime issues.
fix
Always use version 0.4.1 or higher instead of 0.4.0.
affects: 0.4.0
gotchaA security update for `minimist` (GHSA-xvch-5gv4-984h) was included in version 0.2.1. While `minimist` is only a sub-dependency of a development dependency (`ts-node`), it's good practice to update to 0.2.1 or newer to ensure your dev environment is secure.
fix
Update to `ntp-packet-parser` version 0.2.1 or newer, especially if your build process includes `ts-node`.
affects: <0.2.1
Errors
Common errors & fixes
NPM release is broken to due wrong tag, please use 0.4.1
Version 0.4.0 was released with an incorrect tag, leading to a broken package on npm.
fix
Do not install or use `ntp-packet-parser@0.4.0`. Instead, install `ntp-packet-parser@0.4.1` or the latest version.
TypeError: Cannot read properties of undefined (reading 'parse') OR NtpPacketParser is not a function
This usually occurs when attempting to use a CommonJS `require` statement in an ESM project, or incorrectly importing `NtpPacketParser` as a default export instead of a named export.
fix
For ESM, use `import { NtpPacketParser } from 'ntp-packet-parser';`. For CommonJS, use `const { NtpPacketParser } = require('ntp-packet-parser');`.
ReferenceError: Buffer is not defined
The `ntp-packet-parser` library is designed for Node.js environments and expects the global `Buffer` object to be available for handling raw UDP packet data. This error occurs when trying to run the library in a non-Node.js environment (e.g., a browser) without a `Buffer` polyfill.
fix
This library is primarily for Node.js. If you must use it in a browser-like environment, you will need to provide a `Buffer` polyfill (e.g., from `buffer` npm package) and configure your bundler (webpack, rollup, etc.) to use it. Alternatively, consider a browser-specific NTP client if available.
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
ntp-packet-parser — npm install ntp-packet-parser · libregistry