To execute an external program from within Node.js, we use the exec function.
For instance, we write
const exec = require("child_process").exec;
exec("pwd", (error, stdout, stderr) => {
// result
});
to call exec with the command we want to run and the callback that’s called when the command is finished running.
We get its output from stdout.
And we get the command’s error output from stderr.