Video demonstration (https://www.youtube.com/watch?v=XPuEOyyXLrQ)
(Sorry for the crappy video, only got my cellphone to film with 😅)
Hello! I'm gonna quickly walkthrough how you can use nvm (https://github.com/creationix/nvm) or n (https://github.com/tj/n) together with IPFS (https://ipfs.io) to quickly download and cache nodejs versions.
Why would you do this? Sharing is caring, it gives you better performance and reliability!
If someone in your local network already downloaded the version, it would just fetch the version from the person sitting next to you. If you downloaded it in the past, it'll already be cached on your local machine. If millions of people download the something from nodejs.org/dist and brings down the server, you'll still be able to get the version from other people.
This is all thanks to how IPFS works.
So I spent my sunday mirroring the whole registry of versions over at nodejs.org/dist and put those versions into a micro EC2 instance (for bootstrapping this) and started sharing it with IPFS. So now, you can easily download the binaries via IPFS for extra awesomeness points.
But how do you really do this?
Well, it's really simple.
- Have nvm (or n) and IPFS already installed
- Have
ipfs daemonrunning
Then it depends on if you're using nvm or n.
- Set the
NVM_NODEJS_ORG_MIRRORenvironment variable tohttp://localhost:8080/ipns/QmY7Tpnuhc4hxjKLhmC5gHHntB7JFB8Gjt13KsJDKTuVyZ/distwhich points to the directory of versions - Restart your shell or source
~/.nvm/nvm.shagain for it to pickup the environment change
- Set the
NODE_MIRRORenvironment variable tohttp://localhost:8080/ipns/QmY7Tpnuhc4hxjKLhmC5gHHntB7JFB8Gjt13KsJDKTuVyZ/distwhich points to the directory of versions
- Navigate to localhost:8080/ipns/QmY7Tpnuhc4hxjKLhmC5gHHntB7JFB8Gjt13KsJDKTuVyZ/dist, find the version you want to install and somehow put it in your
$PATH
Now when you do nvm install 5 (or n 5.0.0), it's gonna look at QmY7Tpnuhc4hxjKLhmC5gHHntB7JFB8Gjt13KsJDKTuVyZ/dist/v0.5.0 to fetch the version, which could be from any peer.
If you're node crazy in the office, this is guaranteed to speed up everyones use of nvm/n. Also, if you run IPFS on your build servers where you download the right node version, you are guaranteed to always be able to download the version, even if nodejs.org goes down.
If you also want to do the same with npm, check out https://github.com/diasdavid/registry-mirror that is doing the same thing (involving IPFS) but for npm instead of nodejs itself.
Signed, @VictorBjelkholm
^ Write to this guy if you have any questions