Last active
July 18, 2016 19:28
-
-
Save phynet/d8f4780d81c6ead75afb to your computer and use it in GitHub Desktop.
Using node to install something using command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Using npm command packgae | |
var npm = require('npm'); | |
npm.load(function(err) { | |
npm.commands.install(['ffi'], function(er, data) { | |
// log errors or data | |
}); | |
npm.on('log', function(message) { | |
console.log(message); | |
}); | |
}); | |
//Using exec | |
var exec = require('child_process').exec,child; | |
child = exec('npm install ffi', | |
function (error, stdout, stderr) { | |
console.log('stdout: ' + stdout); | |
console.log('stderr: ' + stderr); | |
if (error !== null) { | |
console.log('exec error: ' + error); | |
} | |
}); | |
//http://stackoverflow.com/questions/15957529/can-i-install-a-npm-package-from-javascript-running-in-node-js | |
//https://strongloop.com/strongblog/node-js-v0-12-shell-programming-synchronous-child-process/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment