Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How can I tell npm to install all packages available in its repository? I have to work offline, so I'm preparing a virtual machine to code in node.js and I don't know if I may end up needing some package in the future, so I wish I was able to install all of them beforehand.

share|improve this question

migrated from stackoverflow.com Aug 1 '11 at 5:25

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 4 down vote accepted

A list of all packages can be found here http://registry.npmjs.org/-/all

var request = require('request');
var exec = require('child_process').exec;

request('http://registry.npmjs.org/-/all', function(err, request, body) {
    install(Object.keys(JSON.parse(body)));
});

function install(packages) {
    var pkg = packages.shift();
    console.log('installing ' + pkg + '...');
    exec('npm install ' + pkg + ' -g', function() {
        if (packages.length)
            install(packages);
    });
}
share|improve this answer
    
Being a node.js newbie, I had to install the request module using "npm install request" before it would work –  John Carse Mar 20 '12 at 14:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.