To ping from a Node.js app, we call exec
.
For instance, we write
const sys = require("sys");
const exec = require("child_process").exec;
exec("ping -c 3 localhost", (error, stdout, stderr) => {
sys.puts(stdout);
});
to call exec
to run the ping
command.
And then we get the output from stdout
in the callback.