Slava Ukraini!

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);
});