3 An SNTP v4 client (RFC4330) for node. Simpy connects to the NTP or SNTP server requested and returns the server time
4 along with the roundtrip duration and clock offset. To adjust the local time to the NTP time, add the returned `t` offset
7 [![Build Status](https://secure.travis-ci.org/hueniverse/sntp.png)](http://travis-ci.org/hueniverse/sntp)
12 var Sntp = require('sntp');
14 // All options are optional
17 host: 'nist1-sj.ustiming.org', // Defaults to pool.ntp.org
18 port: 123, // Defaults to 123 (NTP)
19 resolveReference: true, // Default to false (not resolving)
20 timeout: 1000 // Defaults to zero (no timeout)
23 // Request server time
25 Sntp.time(options, function (err, time) {
28 console.log('Failed: ' + err.message);
32 console.log('Local clock is off by: ' + time.t + ' milliseconds');
37 If an application needs to maintain continuous time synchronization, the module provides a stateful method for
38 querying the current offset only when the last one is too old (defaults to daily).
41 // Request offset once
43 Sntp.offset(function (err, offset) {
45 console.log(offset); // New (served fresh)
47 // Request offset again
49 Sntp.offset(function (err, offset) {
51 console.log(offset); // Identical (served from cache)
56 To set a background offset refresh, start the interval and use the provided now() method. If for any reason the
57 client fails to obtain an up-to-date offset, the current system clock is used.
60 var before = Sntp.now(); // System time without offset
62 Sntp.start(function () {
64 var now = Sntp.now(); // With offset