{"library":"ntp-packet-parser","title":"NTP Packet Parser","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install ntp-packet-parser"],"cli":null},"imports":["import { NtpPacketParser } from 'ntp-packet-parser';","import type { NtpPacket } from 'ntp-packet-parser';","const { NtpPacketParser } = require('ntp-packet-parser');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { NtpPacketParser, NtpPacket } from 'ntp-packet-parser';\n\n// A real NTP packet is 48 bytes. This is a mock buffer for demonstration.\n// In a real application, this buffer would be received from a UDP socket.\nconst mockUdpPacket = Buffer.from([\n  0x24, 0x01, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x0a, 0x3d, 0x76,\n  0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6,\n  0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6, 0xe5, 0x09, 0xc1, 0xc6\n]);\n\ntry {\n  const result: NtpPacket = NtpPacketParser.parse(mockUdpPacket);\n\n  console.log('NTP Packet Parsed:');\n  console.log(`  Leap Indicator: ${result.leapIndicator}`);\n  console.log(`  Version: ${result.version}`);\n  console.log(`  Mode: ${result.mode}`);\n  console.log(`  Stratum: ${result.stratum}`);\n  console.log(`  Reference ID: ${result.referenceId}`);\n  console.log(`  Transmit Timestamp: ${result.transmitTimestamp.toISOString()}`);\n\n  // Example of calculating relative time for a Date property\n  const unixEpoch = new Date('Jan 01 1900 GMT').getTime();\n  const rootDelayInMilliseconds = result.rootDelay.getTime() - unixEpoch;\n  console.log(`  Root Delay in milliseconds (relative to 1900): ${rootDelayInMilliseconds}`);\n\n} catch (error) {\n  console.error('Error parsing NTP packet:', error);\n}","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}