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 @chemzqm/ping-lite with all npm packages installed. Try it out:

var pingLite = require("@chemzqm/ping-lite")

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

@chemzqm/ping-lite v2.0.2

A very simple ping wrapper

ping-lite Build Status NPM

A simple ping module for NodeJS apps.

Install

npm install ping-lite

Test

cd node_modules/ping-lite && mocha

Usage

var Ping = require('ping-lite');

var ping = new Ping('8.8.8.8');

ping.send(function(err, ms) {
  console.log(ping._host+' responded in '+ms+'ms.');
});

Events

  • error = When the ._bin throws an error
  • result = When the ._bin completes, no response returns null

Methods

  • #send(callback) accepts an optional callback that returns an error if there's an issue with theh ._bin, a null if there's no response or an Integer if the host responds.
  • #start(callback) calls #send every 5 seconds until #stop is called
  • #stop() stops active pings

Examples

// send one ping & handle results with callbacks
var Ping = require('ping-lite');

var ping = new Ping('8.8.8.8');

ping.send(function(err, ms) {
  console.log(this._host+' responded in '+ms+'ms.');
});
// send pings until stopped & handle results with callbacks
var Ping = require('ping-lite');

var ping = new Ping('8.8.8.8');

ping.start(function(err, ms) {
  console.log(this._host+' responded in '+ms+'ms.');
});

setTimeout(function() {
  ping.stop();
}, 20000);
// send one ping & handle results with events
var Ping = require('ping-lite');

var ping = new Ping('8.8.8.8');

ping.on('error', function(err) {
  console.log('uhoh: ',err);
});

ping.on('result', function(err, ms) {
  console.log(this._host+' responded in '+ms+'ms.');
});

ping.send(); // or ping.start();
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