akamai-time-reference

1.0.1 • Public • Published

Build Status npm version Dependency Status

akamai-time-reference


What is this ?

akamai-time-reference is a Node.js package to get the exact current time using Akamai's Time Reference service.

It has only two depedencies :

What it isn't

  • An NTP client, see ntp-client
  • More generally, a solution to synchronize your local clock
  • A banana

How it works ?

const timeRef = require('akamai-time-reference');
 
timeRef.now().then(function(now) {
  console.log(now);
});
// >> Tue Sep 15 2015 21:36:53 GMT+0200 (CEST)
 
timeRef.now().then(function(refNow) {
  console.log('Local clock desync ins ms : %d', Date.now() - refNow);
});
// >> Local clock desync ins ms : 12765

The now() function can be passed an argument, which, if true, will skip the cache (to force a HTTP request).

const timeRef = require('akamai-time-reference');
 
timeRef.now();
// >> HTTP request
timeRef.now();
// >> NO HTTP request, used cache
timeRef.now(true);
// >> HTTP request

Options

You can change some options like using setOptions by passing it an object with one/some of theses properties :

timeRef.setOptions({
  cacheTTL: 5000, // How often do we make a request to akamai, in ms (<=0 to disable)
  useHTTP: false, // Use the HTTP protocol instead of HTTP**S**
  timeout: 2000, // Request timeout value, in ms
});
 
// or just one :
 
timeRef.setOptions({ cacheTTL: 1000 });
 

(Above example gives you the default values).

Changing an/some options is done for every future calls (in the process), globally.

setOptions will return the current options (You can pass an empty object to just get them).

Readme

Keywords

Package Sidebar

Install

npm i akamai-time-reference

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • c2c