How to "Ping" from a Node.js app?


Question

I want to ping a server from my node.js app.

Is that doable?

Thanks

1
44
1/19/2011 4:19:34 PM

Accepted Answer

You could use exec to call the system ping command

var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("ping -c 3 localhost", puts);
24
1/19/2011 3:55:35 PM

node-net-ping is an awesome module that uses raw sockets.

And, if you are looking for only raw sockets, the same developer has a module for that too: node-raw-socket.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon