a ping wrapper for nodejs
@last-modified: 2025-09-29
(C) Daniel Zelisko
http://github.com/danielzzz/node-ping
node-ping is a simple wrapper for the system ping utility.
npm install ping
Notes:
- Although it is marked with node >=22, it should technially working in all node version for production purpose. The version is marked for development point of view
Below are examples extracted from examples
varping=require('ping');varhosts=['192.168.1.1','google.com','yahoo.com'];hosts.forEach(function(host){ping.sys.probe(host,function(isAlive){varmsg=isAlive ? 'host '+host+' is alive' : 'host '+host+' is dead';console.log(msg);});});varcfg={timeout: 10,// WARNING: -i 2 may not work in other platform like windowsextra: ['-i','2'],};hosts.forEach(function(host){ping.sys.probe(host,function(isAlive){varmsg=isAlive ? 'host '+host+' is alive' : 'host '+host+' is dead';console.log(msg);},cfg);});varping=require('ping');varhosts=['192.168.1.1','google.com','yahoo.com'];hosts.forEach(function(host){ping.promise.probe(host).then(function(res){console.log(res);});});hosts.forEach(function(host){// WARNING: -i 2 argument may not work in other platform like windowsping.promise.probe(host,{timeout: 10,extra: ['-i','2'],}).then(function(res){console.log(res);});});varping=require('ping');varhosts=['192.168.1.1','google.com','yahoo.com'];for(lethostofhosts){letres=awaitping.promise.probe(host);console.log(res);}varping=require('ping');varhosts=['192.168.1.1','google.com','yahoo.com'];for(lethostofhosts){// WARNING: -i 2 argument may not work in other platform like windowsletres=awaitping.promise.probe(host,{timeout: 10,extra: ['-i','2'],});console.log(res);}See PingConfig in types/index.d.ts
- For callback based implementation:
See probeCallback in types/ping-sys.d.ts
- For promise based implementation
See PingResponse in types/ping-promise.d.ts
Since
pingin this module relies on thepingfrom underlying platform, arguments inPingConfig.extrawill definitely be varied across different platforms.However,
numeric,timeoutandmin_replyhave been abstracted. Values for them are expected to be cross platform.By setting
numeric,timeoutormin_replyto false, you can runpingwithout corresponding arguments.
- It does not work with busybox's ping implemetation #89
Try to install package iputils. For example, running apk add iputils
For questions regarding to the implementation of
timeout, anddeadline, please checkout discussions in #101For questions regarding to the defintions of
host,inputHost, andnumeric_host, please checkout discussions in #133
Before opening a pull request please make sure your changes follow the contribution guidelines.
Made with contrib.rocks.