Categories
JavaScript Answers

How to ping from a Node.js app?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *