Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ntp-time

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntp-time

A ntp library for nodejs

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
977
increased by5.05%
Maintainers
1
Weekly downloads
 
Created
Source

ntp-time

NPM

Installation

With npm:

npm install ntp-time

With yarn:

yarn add ntp-time

Methods and usage

Client

To instantiate an NTP Client you just have to require the client class from the module and then instantiate it inside your code. To get the time you must use the syncTime method.

client.js

const NTP = require("ntp-time").Client;
const client = new NTP("a.st1.ntp.br", 123, { timeout: 5000 });

async function sync() {
	try {
		await client.syncTime();
	} catch (err) {
		console.log(err);
	}
}

sync();

// Or using .then

client
	.syncTime()
	.then((time) => console.log(time)) // time is the whole NTP packet
	.catch(console.log);

Server

To put a server up, you must require the server class from the ntp-time module, pass a request callback to it and use the listen method, with a port and an callback as an argument. Inside the request callback you can manipulate the message the way you want.

server.js

const NTPServer = require("ntp-time").Server;
const server = new NTPServer();

// Define your custom handler for requests
server.handle((message, response) => {
	console.log("Server message:", message);
	message.transmitTimestamp = Date.now();

	response(message);
});

server.listen(3000, (err) => {
	if (err) throw err;

	console.log("Server listening");
});

For more didatic code, go to the examples page.

Keywords

FAQs

Package last updated on 22 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc