photography of black dial telephone @gypsycompassrose https://unsplash.com/photos/fnlNwb5sB5Y

Using the exec command in node.js

Published:

Using the exec command in Node.js is pretty simple, first import the exec function, and then call it with the the first argument being the command you are running, and the second argument a callback with params for error, stdout, stderr.

const exec = require('child_process').exec;

const command = `rsync -Pavu "/origin/${special}" "/destination/${show}/"`;

exec(command, function(err, stdout, stderr) {
    if (err) {
        console.log(err);
        return;
    }
    console.log(stdout);
});