# sntp

> SNTP Client

Latest version **3.0.2** (published 2018-11-03) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install sntp
pnpm add sntp
yarn add sntp
bun add sntp
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2018-11-03 |
| First published | 2013-01-21 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | separate (@types/sntp) |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 84 |
| Maintainers | hueniverse |
| Keywords | sntp, ntp, time |

## Links

- npm: https://www.npmjs.com/package/sntp
- Repository: https://github.com/hueniverse/sntp
- Homepage: https://github.com/hueniverse/sntp#readme
- Issues: https://github.com/hueniverse/sntp/issues
- npm.io page: https://npm.io/package/sntp

## Dependencies (4)

- [boom](https://npm.io/package/boom.md) 7.x.x
- [hoek](https://npm.io/package/hoek.md) 6.x.x
- [bounce](https://npm.io/package/bounce.md) 1.x.x
- [teamwork](https://npm.io/package/teamwork.md) 3.x.x

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2018-11-03
- 3.0.1 — 2017-11-04
- 3.0.0 — 2017-10-26
- 2.1.0 — 2017-10-26
- 2.0.3 — 2017-10-26
- 2.0.2 — 2016-12-01
- 2.0.1 — 2016-07-28
- 2.0.0 — 2015-11-05
- 1.0.9 — 2014-09-05
- 1.0.8 — 2014-09-05
- 1.0.7 — 2014-08-02
- 1.0.6 — 2014-04-26
- 1.0.5 — 2014-04-08
- 1.0.4 — 2014-04-08
- 1.0.3 — 2014-02-25
- … 15 more at https://npm.io/package/sntp/versions

## README

# sntp

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](https://secure.travis-ci.org/hueniverse/sntp.png)](http://travis-ci.org/hueniverse/sntp)

# Usage

```javascript
var Sntp = require('sntp');

// All options are optional

var options = {
    host: 'nist1-sj.ustiming.org',  // Defaults to pool.ntp.org
    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');
        process.exit(0);
    }
    catch (err) {
        console.log('Failed: ' + err.message);
        process.exit(1);
    }
};

exec();
```

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).

```javascript
// 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)
};

exec();
```

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.

```javascript
var before = Sntp.now();                    // System time without offset

const exec = async function () {

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

exec();
```

---
_Source: https://npm.io/package/sntp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
