Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including sntp with all npm packages installed. Try it out:

var sntp = require("sntp")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

sntp v3.0.2

SNTP Client


An SNTP v4 client (RFC4330) for node. Simpy connects to the NTP or SNTP server requested and returns the server time along with the roundtrip duration and clock offset. To adjust the local time to the NTP time, add the returned t offset to the local time.

Build Status


var Sntp = require('sntp');

// All options are optional

var options = {
    host: '',  // Defaults to
    port: 123,                      // Defaults to 123 (NTP)
    resolveReference: true,         // Default to false (not resolving)
    timeout: 1000                   // Defaults to zero (no timeout)

// Request server time

const exec = async function () {

    try {
        const time = await Sntp.time(options);
        console.log('Local clock is off by: ' + time.t + ' milliseconds');
    catch (err) {
        console.log('Failed: ' + err.message);


If an application needs to maintain continuous time synchronization, the module provides a stateful method for querying the current offset only when the last one is too old (defaults to daily).

// Request offset once

const exec = async function () {

    const offset1 = await Sntp.offset();
    console.log(offset1);                   // New (served fresh)

    // Request offset again

    const offset2 = await Sntp.offset();
    console.log(offset2);                   // Identical (served from cache)


To set a background offset refresh, start the interval and use the provided now() method. If for any reason the client fails to obtain an up-to-date offset, the current system clock is used.

var before =;                    // System time without offset

const exec = async function () {

    await Sntp.start();
    var now =;                   // With offset



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free