const nodeSsh = require('node-ssh'); const ssh = new nodeSsh(); module.exports = (command) => { return new Promise(function(resolve, reject) { ssh.connect({ host: config.ssh.host, username: config.ssh.user, privateKey: config.ssh.key }) .then(function(){ ssh.execCommand('/usr/bin/sudo -- ' + command, {cwd: config.infrastructure}) .then(function(result) { if(result.code === 0) { resolve(result); } else { reject(result); } }, function(result) { reject(result); }) }, function(result) { reject(result); }); }); };