Skip to content

Instantly share code, notes, and snippets.

@victorb
Last active November 15, 2015 22:09
Show Gist options
  • Select an option

  • Save victorb/af38baab3728414ab478 to your computer and use it in GitHub Desktop.

Select an option

Save victorb/af38baab3728414ab478 to your computer and use it in GitHub Desktop.
Making use of IPFS to download nodejs versions

Using IPFS for downloading and sharing nodejs versions

Video demonstration (https://www.youtube.com/watch?v=XPuEOyyXLrQ)

(Sorry for the crappy video, only got my cellphone to film with 😅)

Demonstration

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 daemon running

Then it depends on if you're using nvm or n.

NVM

  • Set the NVM_NODEJS_ORG_MIRROR environment variable to http://localhost:8080/ipns/QmY7Tpnuhc4hxjKLhmC5gHHntB7JFB8Gjt13KsJDKTuVyZ/dist which points to the directory of versions
  • Restart your shell or source ~/.nvm/nvm.sh again for it to pickup the environment change

N

  • Set the NODE_MIRROR environment variable to http://localhost:8080/ipns/QmY7Tpnuhc4hxjKLhmC5gHHntB7JFB8Gjt13KsJDKTuVyZ/dist which points to the directory of versions

Manual way (AKA the true programmer way)


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment