# IPFS in JavaScript

This guide will walk you through the basics of using IPFS with JavaScript. JS-IPFS is one of multiple IPFS implementations. You will learn how to install and spawn a node using the available libraries, and add, retrieve, read, and remove files. If you are unsure about the meaning of some terms, check out the glossary.


All instructions and examples shown here were performed and tested on an M1 Mac. However, the IPFS commands are the same on Linux, macOS, and Windows. You will to navigate your computer's directories from within the CLI. If you're unsure how to use the CLI, we recommend learning how before continuing with this guide.

There are two ways to work with IPFS using JavaScript; the JS-IPFS library or the HTTP client. We'll show you how to use both in this guide.

# Install JS-IPFS

    # Spawn a node

      # Connect to IPFS

      The JS-IPFS implementation is split into several Node.js modules. The following section shows examples of using the HTTP client to connect to IPFS. For more information on the different modules, examine the API Packages table

        # Add a file

        Now you can start to add files using JS-IPFS to the IPFS network.

        Section changes coming soon

        As the JS-IPFS implementation changes, some of these steps should be deemed conditional. Please reference the source packages (opens new window) for the latest updates.

          # Retrieve a file

            # Pin a file

            Pinning a file will save the file data save to the local IPFS node and ensure data is not lost.

            1. Using the pin add method on the daemon, you can pin a file by running:

              jsipfs pin add QmWcYcWY5vdDzBcAoLo3rYXQ2tLkjzu57vEePCvyhuwZRi
            2. The result should be something like:

              pinned QmWcYcWY5vdDzBcAoLo3rYXQ2tLkjzu57vEePCvyhuwZRi

            By default, objects that you retrieve over IPFS are not pinned to your node. If you wish to prevent the files from being garbage collected, you need to pin them. You will notice that the pin you just added is a recursive pin, meaning it is a directory containing other objects. Check out the pinning content to learn more about pinning.

            # Remove a file

            Removing a file from IPFS does not guarantee that it was completely removed from the network.

            There is no way to know if someone else has made a copy of the content from when it became available on the network. This caveat is also found in regular HTTP networks, as nothing stops users from addressing content and creating a copy once it is pushed to IPFS.

            Removing the content pin will remove a file from IPFS. In this section, we will remove the pinned test.txt file we pinned earlier.