DEV Community

mibii
mibii

Posted on

How to Run Your Own IPFS Node and Share Files

A Beginner’s Guide

As a programmer on a journey to master different technologies, there’s nothing more satisfying than learning how to build decentralized solutions. One such technology that's gaining traction is IPFS (InterPlanetary File System), a protocol for creating distributed, peer-to-peer networks for storing and sharing files. Today, I’ll walk you through running your own IPFS node, uploading files, and ensuring they’re available across the global IPFS network.

Image description

What is IPFS?

IPFS is a decentralized system designed to make the web more resilient by spreading content across multiple nodes instead of relying on a central server. In IPFS, every file is identified by a CID (Content Identifier), a unique cryptographic hash. This CID is crucial for retrieving the file from the IPFS network.

Setting Up Your Own IPFS Node

Before we dive into running your node, let’s first cover the basics of installation and initialization. If you're already familiar with setting environment variables and command-line tools, this will feel straightforward.

Step 1: Install IPFS

First, you’ll need to install Kubo (formerly called go-ipfs), the reference implementation of the IPFS protocol. Follow these steps:

Download IPFS and unzip the files to a directory, e.g., C:\Users\YourName\kubo.
Add the Kubo binary directory to your system’s PATH environment variable:

$Env:PATH += ";C:\Users\YourName\kubo"
Verify that IPFS is installed correctly by running:
Enter fullscreen mode Exit fullscreen mode
ipfs --version
Enter fullscreen mode Exit fullscreen mode

Step 2: Initialize Your IPFS Node

Once installed, initialize your node:

ipfs init
Enter fullscreen mode Exit fullscreen mode

This command creates a local repository (by default in C:\Users\YourName.ipfs) and generates a peer identity. Your node is now ready to connect to the network.

Step 3: Start the IPFS Daemon

Now, it’s time to start your IPFS node:

ipfs daemon
Enter fullscreen mode Exit fullscreen mode

You’ll see your node connect to other peers in the network, and the WebUI will be available at http://127.0.0.1:5001/webui.

Adding and Pinning Files on IPFS
Enter fullscreen mode Exit fullscreen mode

Once your node is running, you can start adding and pinning files to make them available on the IPFS network. You can do it via WebUI http://127.0.0.1:5001/webui and via console - see below:

Step 4: Add Files to IPFS

To add a file to IPFS and get its CID, use the following command:

ipfs add path-to-your-file
Enter fullscreen mode Exit fullscreen mode

For example, if you want to upload a file called post.json, the command will be:

ipfs add C:\Users\YourName\Desktop\post.json
Enter fullscreen mode Exit fullscreen mode

You’ll get back a CID, which is the key to accessing your file on the network.

Step 5: Pinning the File
Enter fullscreen mode Exit fullscreen mode

When you add a file to your local node, it automatically gets pinned. Pinning ensures the file stays on your local node even if it's requested by others. The great part? You can use the WebUI to manage pins, making it user-friendly to see the status of your pinned files.

Accessing Files via Public IPFS Gateways
Enter fullscreen mode Exit fullscreen mode

Once you have the CID, you can access your file from any IPFS gateway. For example, let’s say the CID of your file is QmWS2n1SihYJ9eDSGhxQUDo2zCdfk1zRQjXq43jsywjYB2.

You can view the file through public gateways like:

https://gateway.pinata.cloud/ipfs/QmPsp3WXwRyNghtkXRg7eFcxNdcCe4pSboYvTydoVZFhK2

Why Might the File Not Show Up?

When you first add a file, it might not be immediately available from public gateways. This is because public gateways need to discover your file through the distributed network. You may need to wait a bit, or try the following:

Provide the CID to the network using:

ipfs routing provide <CID>
Enter fullscreen mode Exit fullscreen mode

This helps announce your file’s availability on the DHT (Distributed Hash Table).

Check Swarm Peers: Ensure your node is connected to enough peers:

ipfs swarm peers
Enter fullscreen mode Exit fullscreen mode

Keep Your Node Online: If your node is offline, public gateways won't be able to fetch the file. Once your file becomes widely available, though, it should persist on the network, even if your node goes offline.

Decentralized blog

Now let's review the possible practical use of IPFS in implementing the practical thing. Here is for example the post blog that doesn't need any server at all. I place the interface page on netlify, also i place the interface at ipfs https://gateway.pinata.cloud/ipfs/QmPsp3WXwRyNghtkXRg7eFcxNdcCe4pSboYvTydoVZFhK2 but actually it is not required, you may save page locally on your PC and it is will be working fine. (Gitgub link to webpage source)

The page looks next:

Image description

To get the post just - click on dropdown text list.

  • in a first dropdown text list - select the predefined my post CID address. Or past manually the address that you will receive from me later.
  • in the second dropdown text list - select the the url link of any publik ipfs gateway or if you have a localy runing ipfs node select next url http://127.0.0.1:8080/ipfs/

That it , you are ready to see my post:
for example:

Image description

Final Thoughts

Learning how to run your own IPFS node and contribute to the decentralized web is a great step in mastering distributed technologies. While it may seem complex at first, running your own node provides you with full control over how your files are stored and shared.

Experiment with adding more files, pinning them, and accessing them through different gateways. In time, you’ll appreciate the resilience and innovation that IPFS brings to the web!

Happy coding! 🚀

Top comments (0)