How To Get Started With IPFS and Node

Learn what the InterPlanetary File System is and how to store data with it

Indrek Lasn
Aug 7, 2019 · 5 min read
Image for post
Image for post
Run IPFS on Node.js and the Browser —

IPFS (the InterPlanetary File System) is a new hypermedia distribution protocol, addressed by content and identities. IPFS enables the creation of completely distributed applications. It aims to make the web faster, safer, and more open.

IPFS is a distributed file system that seeks to connect all computing devices with the same system of files. In some ways, this is similar to the original aims of the Web, but IPFS is actually more similar to a single BitTorrent swarm exchanging git objects. You can read more about its origins in the paper IPFS — Content Addressed, Versioned, P2P File System.

IPFS is becoming a major new subsystem of the internet. If built right, it could complement or replace HTTP. It could complement or replace even more than that. It sounds crazy. It is crazy.

The Current State of IPFS

Image for post
Image for post

Please note that IPFS is a work in progress. It is an ambitious plan to make the internet more free, open, and secure, and to have higher performance. It builds on the good ideas of numerous battle-tested distributed systems.

Getting Started

To get started we’re going to need Node.js installed and a text editor.


Now that we have Node installed, let’s get cooking. Start with creating a new Node project.

npm init -y

Now we have the package.json file which lets us install node modules. Go ahead by and install the ipfs node module.

npm install ipfs

Good job! Next, we need to create a index.js file, in which we’ll place our application logic.

touch index.js

Inside index.js place the following logic.

We simply import the IPFS module and initially our node application with the main() function.

Now we’ve written the boilerplate code, it’s time to implement the IPFS code itself.

Let’s spawn an IPFS node. It will look like this:

If you run this code with Node you should see your console alerting you with messages regarding the IPFS:

node index.js
Image for post
Image for post
Spawning IPFS nodes

Excellent! This means everything is working as expected. If you're not seeing this, try installing the ipfs package again.

Since we spawned an IPFS node, let’s put it to use. Start by adding a file to the IPFS node. Once we add the node, we can retrieve the file back using the cat call.

Voila! Check the console for the fileBuffer.

Image for post
Image for post

That's it! You just added and retrieved a file from the Distributed Web. Find the source code here.

We barely scratched the surface here — if you’re curious to learn more, here’s a full repository of more examples.

Understanding the IPFS Stack

In this section, you’ll find explanations ofdifferent pieces of IPFS Architecture and how js-ipfs implements them.

Image for post
Image for post

Quick Summary

IPFS is a protocol that:

  • defines a content-addressed file system
  • coordinates content delivery
  • combines Kademlia + BitTorrent + Git

IPFS is a filesystem that:

  • has directories and files
  • mountable filesystem (via FUSE)

IPFS is a web:

  • can be used to view documents like the web
  • files accessible via HTTP at<path>
  • browsers or extensions can learn to use the ipfs:// URL or dweb:/ipfs/ URI schemes directly
  • hash-addressed content guarantees the authenticity

IPFS is modular:

  • connection layer over any network protocol
  • routing layer
  • uses a routing layer DHT (kademlia/coral)
  • uses a path-based naming service
  • uses BitTorrent-inspired block exchange

IPFS uses crypto:

  • cryptographic-hash content addressing
  • block-level deduplication
  • file integrity + versioning
  • filesystem-level encryption + signing support

IPFS is p2p:

  • worldwide peer-to-peer file transfers
  • completely decentralized architecture
  • no central point of failure

IPFS is a CDN:

  • add a file to the filesystem locally and it’s now available to the world
  • caching-friendly (content-hash naming)
  • BitTorrent-based bandwidth distribution

IPFS has a name service:

  • IPNS, an SFS inspired name system
  • global namespace based on PKI
  • serves to build trust chains
  • compatible with other NSes
  • can map DNS, .onion, .bit, etc to IPNS

How IPFS works

To learn more about how IPFS works take a look at the Papers or Talks. You can also explore the Specs in writing.

Where to Go From Here

There’s so much more IPFS can do. If you’re curious to learn, I suggest going through this free interactive tutorial. Interactive tutorials help you learn about the decentralized web by writing code and solving challenges.

Image for post
Image for post
Free IPFS Interactive Tutorial

In case you want to bring your JavaScript game to the next level, I’d suggest grabbing the “You Don’t Know JS” book series. I found it to be easy to understand and useful. Combine reading with building, here’s a list of fun apps to build.

Thanks for reading and stay awesome!

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store