source
What Will I Learn?
- How to Initialize and configure a local IPFS node
- Upload files to your local IPFS node with CLI
- Track files from your local IPFS node with CLI
Requirements
- Laptop or Desktop Computer (Windows, Linux or Mac)
- IPFS CLI
- Several different files to upload (gif, mp4, .png etc.)
Difficulty
- Intermediate
Initialize a Local IPFS Node
Initializing the IPFS daemon is very simple, just download the compatible version of your computer and install it.
After installation is complete, start the daemon with the command line.
ipfs init
Enter the ipfs init command to start the daemon. This will create a local IPFS node on your machine.
After ipfs is initialized, it will create a readme file. Enter the following command to view the readme file.
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
./readme
You can explore other files(about, help, quick-start, security-notes) in there.
Configure the IPFS Node
The daemon configuration file is kept as a json file. Run the following command to view this configuration.
ipfs config show
To edit the configuration, run the following command. for example, you can change ports for API or Gateway.
"API": "/ip4/127.0.0.1/tcp/5001",
"Gateway": "/ip4/127.0.0.1/tcp/8080"
If you want to allow or deny HTTP POST requests, you can also set this with the config file.
"HTTPHeaders": {
"Access-Control-Allow-Headers": [
"X-Requested-With"
"Range"
]
"Access-Control-Allow-Methods": [
"GET,POST"
]
"Access-Control-Allow-Origin": [
"*"
]
}
Upload files to your local IPFS node with CLI
To upload a file to IPFS, run the IPFS daemon with the following command.
ipfs daemon
You can create a folder on the desktop for the files you want to upload. I created a folder named 'examples'
I have added a few files to the examples folder to upload them to the IPFS node
To upload a file to the IPFS node, open a command prompt in the directory where the file is located and run the following command in CLI.
$ ipfs add FILE_NAME
# Examples
$ ipfs add image.png
$ ipfs add note.txt
With the HASH returned from the CLI, you can access your file via the local IPFS gateway.
http://localhost:8080/ipfs/ {HASH}
Track files from your local IPFS node with CLI
Tracking files from the local IPFS node is very easy with the CLI. To read a file, you only need HASH of that file. You can read the file with ipfs cat FILE_HASH command.
ipfs cat FILE_HASH
ipfs cat QmfDCcLFMFCASvuWuLzFeQcVyFb8Pj3cpPvLPFWozbTETY
An example is shown below. I uploaded a Markdown file to the IPFS node and tried to read it with "ipfs cat" command.