All the JS

May 18th 16

I was fed up waiting so long for all my npm packages to install - especially gyp native ones. Private local caches seem like the way to go.

I thought that it would be funny to see what the maximum download time for the largest package.json. Also the idea that if you could technically use it and be able to require anything.

So I created a script to pull in all of the available npm packages.

Considering that there are 150,000 modules available on npm it is unsurprising that I didn’t have the patience to download all of them.

When I was running it I did make a logo in the tribute of one of my favourite childhood toys Megazord.

MEGA JS

This is the script:

var fs = require('fs'),
  request = require('request'),
  url = '//registry.npmjs.org/-/all',
  filePath = './package.json';

var updatePackages = function(cb) {
  request(url, function(err, response, body) {
    if (err) throw err;
    if (response.statusCode === 200) {
      var data = JSON.parse(body),
        json = {};
      for (var package in data) {
        json[package] = 'latest';
      }
      cb(json);
    }
  });
};

var readFile = function(cb) {
  fs.readFile(filePath, 'utf8', function(err, data) {
    if (err) throw err;
    var content = JSON.parse(data);
    cb(content);
  });
};

var writeFile = function(data) {
  fs.writeFile(filePath, JSON.stringify(data), function(err) {
    if (err) throw err;
    console.log('Updated!');
  });
};

updatePackages(function(json) {
  readFile(function(content) {
    content.dependanices = json;
    writeFile(content);
  });
});

Check the source here.

Progress Albums

Next