Here in our ProtoSchool tutorials, we create a new IPFS node for you in the browser each time you hit the "Submit" button in a lesson. Whenever you see
ipfs.someMethod() in our lessons,
ipfs is a variable that refers to your IPFS instance, also known as a node. The actions that you take only affect your own IPFS node, not nodes belonging to your peers.
We're creating your IPFS node behind the scenes so you can focus on the content of our lessons, but eventually you'll need to learn to host your own node locally by installing IPFS and running a daemon in your terminal. When you're ready to experiment, you can find instructions for installing IPFS and initializing your node in our docs.
As mentioned previously, methods associated with the Mutable File System are part of the Files API, so they'll take the format of
ipfs.files.someMethod(). Let's take a look at a simple method you can start using even before you've added any files to your IPFS node.
When working with your IPFS node, you'll often want to check the status of a file or directory. You can do this with
ipfs.files.stat, passing in the path you'd like to check on.
For example, to check the status of a directory called
stuff located within our root directory (
/ ), we could call the method like so:
This method returns an object with some essential data about our file or directory:
directory, this is the number of files in the directory; if type is
file, it's the number of blocks that make up the file)
size of a directory is always
0, no matter how many entries it contains, since directories are really just a set of links to other files and directories. A directory's
cumulativeSize, by contrast, changes as the directory's contents change. It represents not just the file sizes of all the entries in that directory, but also the metadata that describes those entries: types, block sizes and so on.
It's important to note that you can
stat your IPFS node even when you don't have anything in it yet. Even an empty node has a CID.
files.stat to check the status of your root directory (
/ ) in IPFS. Be sure to return your result.
Feeling stuck? We'd love to hear what's confusing so we can improve this lesson. Please share your questions and feedback.