# Install IPFS for JavaScript (js-ipfs)

WARNING

# js-ipfs being discontinued

Development of the js-ipfs project (opens new window) is being discontinued to focus on Helia (opens new window), a leaner, more modular, modern implementation of IPFS in JavaScript scheduled for release in 2023. To learn more about Helia and the current state of IPFS in JS, see the blog post (opens new window).

Because of this, js-ipfs tutorials may be out of date, and will eventually be archived.

This guide will walk you through the basics of using JS-IPFS, an implementation of IPFS in 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.

Environment

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.