Skip to content

Instantly share code, notes, and snippets.

@m00zi
Forked from miguelmota/cmd.js
Created May 31, 2018 06:57
Show Gist options
  • Save m00zi/920b8253502a0813d9ad76edb1d6505f to your computer and use it in GitHub Desktop.
Save m00zi/920b8253502a0813d9ad76edb1d6505f to your computer and use it in GitHub Desktop.
Node.js run command in child process promise
const exec = require('child_process').exec;
const cmd = 'echo "hello"';
function echo() {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) return resolve(false);
if (stderr) return resolve(false);
resolve(true);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment