To run shell script file using Node, we use the exec function.
For instance, we write
const { exec } = require("child_process");
const yourscript = exec("sh hi.sh", (error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
to call exec to rub the sh hi.sh command.
We get the output from the stdout parameter in the callback.
And we get error output from the stderr parameter in the callback.