Skip to content

Instantly share code, notes, and snippets.

@jammycakes
Created Feb 28, 2012
Embed
What would you like to do?
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