npm install <package name> and go to the loo, have a chat with your crush (Oath #2 of being engineers, no girlfriends), console her, make a cup of coffee, watch a netflix series and come back to desk, and it's almost finished installing your packages.
NPM is infuriating and painfully slow, here's how can we speed it up
We all know the basic "funda" of NPM; It is a centralized repository from where we can "pull" any package. So, everytime you want to add
express to your repository, you have download express again. the npm cli does some smart caching to mitigate this but that's not foolproof.
In order to speed up NPM, we need to use a "NPM Proxy" or "Self hosted registry". The way it works is quite simple, when you request something from npm, this software intercepts the download and saves a copy on the disk, the next time you request the same module, it serves from disk.
Meet Verdaccio, a stable, battle tested NPM Proxy set to speed up your workflow by 2x
And how do you install a npm registry? Using npm, of course.
npm install -g verdaccio
If you are just trying to speed up your own machine, just run
npm config set registry http://localhost:4873 and don't read further.
But if you want some more configuration options and some "enterprise-y" setup, read on.
Use Case Scenarios I will be covering
- If you have a fast and reliable connection, npm works pretty well, but since we all are working from home, and you're reading this, I suspect that might not be the case. If your internet goes down for a minute you can't
- Another problem with npm is that it is a pain in the ass to deploy in secure environments without internet access. And the domain that I work on, that is almost always the case.
Scenario 1: Your local machine(s) or your office.
If you have multiple devices or are a team, you likely download redundant files.
npm install on 5 computers? 5 times the bandwidth. Even if you have super ultra fast internet, you are limited by npm's speed and availability.
If you have a computer that runs 24x7 (or a server even) then, you should totally use it as a local cache for the entire builing (or LAN).
The setup goes like this
The advantage of this to minimize time and configuration. On any other machine you need to run the following.
npm config set registry http://<LAN_IP>:4873
The disadvantage would be that, it is not suitable as a private authenticated repository. It is not really secure, no SSL or anything fancy. It doesn't even have replication and thus, not really reliable. But fast and simple.
Scenario 2: Offline Deployment
In this case, you need set up Verdaccio in a reachable host. Configure everything as above. And copy all the files in your existing directory mentioned
storage block above. And that's all it is.