nodejs-tcp-ping
v1.0.3
Published
TCP Ping is a Node.JS based TCP ping utility written in Typescript.
Downloads
2,513
Maintainers
Readme
nodejs-tcp-ping
TCP Ping is a Node.JS based TCP ping utility written in Typescript
Getting Started
If you are using yarn (RECOMMENDED!)
yarn add nodejs-tcp-ping
If you are using npm
npm install nodejs-tcp-ping --save
Using with JavaScript
const nodejsTcpPing = require('nodejsTcpPing');
// If you are not specify any options
// then ping localhost:80 five times
// with 5000ms timeout
nodejsTcpPing.tcpPing().then(results => {
// It return an array of ping data
// The returned data array (result) is looks like this,
// if everthing was successful: [{ ping: number }, ...]
// if some attempts timedout: [ { ping: null, error: 'Connection timed out' } ]
}).catch(reason => {
// Or a reason why it failed
});
// There is the full specification of options
nodejsTcpPing.tcpPing({
attempts: 5,
host: 'localhost',
port: 80,
timeout: 5000
}).then(results => {
// It return an array of ping data
}).catch(reason => {
// Or a reason why it failed
});
Using with TypeScript
import { tcpPing, IPingData } from 'nodejsTcpPing';
tcpPing().then((result: IPingData[]) => {
// ...
}).catch((reason: any) => {
// ...
});
// Or
tcpPing({
attempts: 5,
host: 'localhost',
port: 80,
timeout: 5000
}).then((result: IPingData[]) => {
// ...
}).catch((reason: any) => {
// ...
});
Testing with yarn
1. Install all the dependencies with yarn
yarn
2. Build the lib with yarn
yarn build
3. Run all the tests with yarn
yarn test
Testing with npm
1. Install all the dependencies with npm
npm install
2. Build the lib with npm
npm run build
3. Run all the tests with npm
npm test