Node.js npm install all packages

node.js

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.

Best Answer

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);
    });
}