by Siddharth Kshetrapal

npm cache: the unsung hero

I love npm and believe that this package manager is the single biggest reason for JavaScript’s massive success these past few years.

There was a lot of excitement in the JavaScript community when facebook released yarn. And for good reason. Yarn’s install speeds are amazing. Subsequent installs are even faster because yarn caches installed modules on your machine.

Install speeds @ 12Mbps. Yarn = ?

But there’s an npm feature that does not get nearly the attention it deserves.

Like Yarn, npm also has a built-in caching mechanism that can make subsequent installs super fast.

Here are some benchmarks:

npm + cache is as fast as yarn + cache (if not faster)

That’s crazy, right? And guess what: this feature has been available to you this whole time, but it’s disabled by default.

How to enable npm cache

npm config set cache-min 9999999

That’s it.

Now install your packages as usual:

npm install express

You can try out these benchmarks for yourself using this repository:

siddharthkp/npm-cache-benchmark
npm-cache-benchmark - Benchmark npm cache vs yarngithub.com

Note that Yarn is not just about speed — it has other features like consistent installs, which set it apart.

But, if speed is an important consideration for you — as it sure is for me — you should give npm another try, this time with cache.

Thanks to ashley williams for reviewing this and to npm, for being awesome.

P.S. You should totally follow me on twitter.