NPM MODULE STATS

NPM MODULE STATS

Most of the times, As a developer I am worried that the third-party modules are bloating my project and wished I could find the size of the module before I add to the project.

Later, I spent couple of nights and came up with this NPM module. This module gets the Exact compressed size of any NPM Module without installing/downloading it in your machine. The size recursively includes the size of its dependency tree till leaf.

Use cases

  • At some point, you want to keep your project as small as possible. However if the NPM modules that you use might increase the overall project size.
  • Just in case, if your are curious to know what are the dependent modules that will be downloaded with any NPM module.

Lessons Learnt

content-length: You don’t have to download a content to get its size.
var req = https.request(options, res => {

//get the zipped size

const len = parseInt(res.headers["content-length"]);
// len gives the size in bytes       

});
Approximate G-zip compression ratio is 1:3
Aysnc/Await may remove lot of clutter in code
Array.indexof is faster than “in” operator
Object.keys(Object).indexOf("String")
Retrying with https request
var req = https.request(options, res => {        

});
req.on("error", e => { 

//retry for 10 times in 500ms interval

if (retry < 10) {
process.stdout.write(`\r Retrying module ${module}`);
retry++;
setTimeout("Your retry function", 500);
} else {
console.error(e);
}
});
req.end();
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.