Skip to content

Instantly share code, notes, and snippets.

@jammycakes
Created February 28, 2012 00:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jammycakes/1928258 to your computer and use it in GitHub Desktop.
Save jammycakes/1928258 to your computer and use it in GitHub Desktop.
Node.js script to install dependencies using npm
var child_process = require('child_process');
function install(modules, callback) {
if (modules.length == 0) {
if (callback) callback(null);
return;
}
var module = modules.shift();
child_process.exec(
'npm install ' + module,
{},
function(error, stdout, stderr) {
process.stdout.write(stdout + '\n');
process.stderr.write(stderr + '\n');
if (error !== null) {
if (callback) callback(error);
}
else {
install(modules, callback);
}
});
}
/* Example */
install([
'coffee-script',
'express'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment