Skip to content

Instantly share code, notes, and snippets.

@phynet
Last active July 18, 2016 19:28
Show Gist options
  • Save phynet/d8f4780d81c6ead75afb to your computer and use it in GitHub Desktop.
Save phynet/d8f4780d81c6ead75afb to your computer and use it in GitHub Desktop.
Using node to install something using command line
//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