- package.json - NPM package configuration with bin entry for CLI
- tsconfig.json - TypeScript compiler configuration
- LICENSE - MIT License
- README.md - Complete API documentation & features
- QUICKSTART.md - Quick start guide with examples
- EXAMPLES.md - Code examples for common use cases
- SHOWCASE.js - Display package features & stats
-
parser.ts - NTP packet parser & timestamp conversion
NTPParserclass for parsing 48-byte NTP packets- Converts NTP timestamps to Unix/JavaScript Date
- Handles 32-bit fraction to milliseconds conversion
- Interfaces:
ParsedNTPPacket,ParsedNTPTimestamp,NTPPacketHeader
-
client.ts - NTP UDP client
NTPClientclass for querying NTP servers- Methods:
query(),getTime(),getOffset() - Creates and sends NTP request packets
- Interfaces:
NTPClientConfig,NTPQueryResult
-
index.ts - Core module exports
- Exports:
NTPClient,NTPParser - Default export with convenience functions
- Exports:
- index.ts - Command-line interface (executable)
HixbeTimeCLIclass with multiple output modes- Options:
--json,--verbose,--offset,--continuous - Custom server support with
--server - Help, version, and all standard CLI features
- index.ts - Main package entry point
- Exports all public API:
NTPClient,NTPParser - Type exports for TypeScript consumers
- Re-exports from core module
- Exports all public API:
- Automatically generated from TypeScript source
- Includes:
- Compiled
.jsfiles (ES2020 modules) - Type definition
.d.tsfiles - Source maps for debugging
- Compiled
npm run build # Compile TypeScript to JavaScript
npm run dev # Watch mode (auto-compile on changes)npm start # Run default CLI query
npm run cli # Alias for npm start
node dist/cli/index.js [OPTIONS] # Direct CLI execution-s, --server <host> # NTP server (default: time.hixbe.com)
-j, --json # JSON output
-v, --verbose # Detailed output with raw bytes
-o, --offset # Offset in milliseconds only
-c, --continuous # Continuous sync mode
-i, --interval <ms> # Sync interval (default: 5000ms)
-h, --help # Show help
--version # Show version@hixbe/time (package)
├── Main Entry: dist/index.js
├── CLI Binary: dist/cli/index.js (for hixbe-time command)
├── Types: dist/*.d.ts (TypeScript definitions)
├── Core:
│ ├── NTPClient - Query NTP servers
│ ├── NTPParser - Parse packets & convert timestamps
│ └── Interfaces - TypeScript types
└── Documentation & Examples
class NTPClient {
constructor(config?: NTPClientConfig)
async query(): Promise<NTPQueryResult>
async getTime(): Promise<Date>
async getOffset(): Promise<number>
}class NTPParser {
static parsePacket(buffer: Buffer): ParsedNTPPacket
static calculateMetrics(...): { roundTripDelay, clockOffset }
}ParsedNTPPacket- Complete parsed NTP packetParsedNTPTimestamp- Converted timestamp with multiple formatsNTPPacketHeader- Packet header informationNTPTimestamps- All four timestamps from packetRawNTPTimestamp- Raw NTP timestamp componentsNTPClientConfig- Client configuration optionsNTPQueryResult- Full query result with raw & parsed data
Server: 154.26.137.94 (time.hixbe.com)
UTC Time: 2025-12-16T04:27:07.341Z
Local Time: Tue Dec 16 2025 10:27:07 GMT+0600
Offset: +0.480 seconds
Precision: ±231 (2^x sec)
Stratum: 2
{
"timestamp": 1765859251781,
"iso": "2025-12-16T04:27:31.781Z",
"server": {
"address": "154.26.137.94",
"stratum": 2,
"referenceId": "0xD8EF230C"
},
"offset": 524
}- System Time Verification - Check if local clock is accurate
- Time Synchronization Daemon - Keep system time in sync
- Distributed System Coordination - Ensure all nodes have same time
- Network Monitoring - Check NTP server responsiveness
- Time-Critical Applications - Get precise server time
- DevOps/Infrastructure - Automated clock monitoring
- Scientific Computing - High-precision timestamps
# 1. Install dependencies
npm install
# 2. Make changes in src/
# (Use npm run dev for watch mode)
# 3. Build
npm run build
# 4. Test CLI
npm start
node dist/cli/index.js --json
# 5. Test in code
import { NTPClient } from './dist/core/index.js'# 1. Update version
npm version patch
# 2. Build (runs automatically)
npm run build
# 3. Publish
npm publish --access public
# 4. Users can then:
npm install @hixbe/time- Byte-by-Byte Conversion - Shows exact conversion process
- Multiple Output Modes - Default, JSON, verbose, offset-only
- Continuous Monitoring - Real-time sync with visual indicators
- Zero Dependencies - Only uses Node.js built-ins
- Type Safe - Full TypeScript support
- RFC 5905 Compliant - Standard NTP protocol
- Beautiful CLI - Emoji and formatted output
- Production Ready - Battle-tested code quality
import { NTPClient, NTPParser } from '@hixbe/time';
// Get time from server
const client = new NTPClient();
const time = await client.getTime();
console.log(time); // Date object
// Get offset
const offset = await client.getOffset();
console.log(`Clock is ${offset > 0 ? 'slow' : 'fast'} by ${Math.abs(offset)}ms`);
// Full packet analysis
const result = await client.query();
console.log(result.parsed.header.stratum);
console.log(result.hexDump);- ✅ TypeScript type safety
- ✅ Comprehensive documentation
- ✅ Multiple output formats
- ✅ Error handling
- ✅ Configuration options
- ✅ Zero dependencies
- ✅ RFC 5905 compliance
- ✅ Production-ready code
- ✅ Beautiful CLI UI
- ✅ Ready for NPM publishing
Package: @hixbe/time v1.0.0
License: MIT
Author: Hixbe
Type: ESM (ES Module)
Node Version: >=18.0.0
Location: j:\ntp-playground