# Filebase NPM Package

## What is the Filebase NPM package?

The Filebase NPM package is a client library for the <https://filebase.com/> service. It provides a convenient interface for working with the Raw HTTP API from a web browser or Node.js and comes bundled with TS for out-of-the box type inference and better IntelliSense.

Read below to learn how to use the Filebase NPM package for pinning files to IPFS.

{% hint style="success" %}

### Prerequisites:

* [x] Download and install [NodeJS](https://nodejs.org/en/download/) version 14.20.0 or newer.
* [x] [Sign up](https://filebase.com/signup) for a free Filebase account.
* [x] Have your Filebase Access and Secret Keys. Learn how to view your access keys [here](https://docs.filebase.com/getting-started-guides/getting-started-guide#working-with-access-keys).
* [x] Create a Filebase IPFS Bucket. Learn how to create a bucket [here](https://docs.filebase.com/getting-started-guides/getting-started-guide#creating-and-working-with-buckets).
  {% endhint %}

## Installing the Filebase npm package

Install the package using npm:

`npm i @filebase/client`

Or install the package using yarn:

`yarn add @filebase/client`

## Pinning New Files

```jsx
import { FilebaseClient, File } from '@filebase/client'
const filebaseClient = new FilebaseClient({ token: 'API_TOKEN' })

const metadata = await filebaseClient.store({
    name: 'Example',
    description: 'An example image.',
    image: new File(
      [
        /* data */
      ],
      'example.jpg',
      { type: 'image/jpg' }
    ),
})
console.log(metadata.url)
// ipfs://bafyreib4pff766vhpbxbhjbqqnsh5emeznvujayjj4z2iu533cprgbz23m/metadata.json
```

Replace the following values to reflect your configuration:

* **API Token:** Your Filebase API Token. You can learn how to obtain this value [here](/api-documentation/ipfs-pinning-service-api.md).
* **Name**: Your file name.
* **Description**: Your file description
* **example.jpg**: The name of the file to be pinned.&#x20;

{% hint style="warning" %}
**Note**: The client uses ESM modules. If running from Node.js, either name your script `index.mjs` or name it `index.js` and use `npm init` to create a new `package.json` file in your project directory, adding `"type": "module",` to it.
{% endhint %}

Alternatively, you can pass text content directly in the script to be uploaded as a new file:

```jsx
import { FilebaseClient } from '@filebase/client'
const filebaseClient = new FilebaseClient({ token: 'API_TOKEN' })

const content = new Blob(['hello world'])
const cid = await filebaseClient.storeBlob(content)
console.log(cid);
// Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD
```

## Running the Script

`node index.js`

The output will resemble the following:

<figure><img src="/files/2qNuU3X6Jk8CQIpfNNDq" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.filebase.com/code-development-+-sdks/code-development/filebase-npm-package.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
