How To Get Started With IPFS and Node
Learn what the InterPlanetary File System is and how to store data with it
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
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.
To get started we’re going to need Node.js installed and a text editor.
- Text editor/IDE
- Node — please head to the official node website for installation instructions
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.
index.js place the following logic.
We simply import the
IPFS module and initially our node application with the
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:
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
Voila! Check the console for the
That's it! You just added and retrieved a file from the Distributed Web. Find the source code here.
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
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.
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
- browsers or extensions can learn to use the
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
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.
ProtoSchool is an educational community that teaches decentralized web protocols and tools through online tutorials and…
2020 Programming Trend Predictions
Predicting what programming technologies will emerge in 2020
The Secret to Being a Top Developer Is Building Things! Here’s a List of Fun Apps to Build!
Thanks for reading and stay awesome!