Filebase NPM Package
Learn how to use the Filebase NPM package for pinning files to IPFS.
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.
Install the package using npm:
npm i @filebase/client
Or install the package using yarn:
yarn add @filebase/client
const fsPath = require("path");
const { FilebaseClient } = require('@filebase/client')
const { filesFromPath } = require('files-from-path')
async function upload (api, options) {
console.log(`Parsing options...`);
const { path, pinName, verbose } = options;
let source = path;
if (!fsPath.isAbsolute(source)) {
const dir = process.cwd().toString();
source = fsPath.join(dir, source);
}
console.log(`Adding files...`);
const files = [];
for await (const file of filesFromPath(source, { pathPrefix: source })) {
files.push(file)
if (verbose) {
console.log(`Added File: ${JSON.stringify(file)}`);
}
}
console.log(`Storing files...`);
let tokenString = `${api.key}:${api.secret}:${api.bucket}`;
let cid = await FilebaseClient.storeDirectory(
{ endpoint: 'https://s3.filebase.com', token: Buffer.from(tokenString).toString('base64') },
files,
pinName
);
console.log(`Stored files...`)
console.log(`CID: ${cid}`);
console.log(`Done`)
return {
cid: cid,
ipfs: cid,
};
}
(async function () {
try {
await upload({
key: "FILEBASE_KEY",
secret: "FILEBASE_SECRET",
bucket: "FILEBASE_BUCKET",
}, {
path: "testFiles",
pinName: "myFirstIpfs3Pin"
});
} catch (err) {
console.error(err.message);
}
})();
Replace the following values to reflect your configuration:
- Key: Filebase Access Key
- Secret: Filebase Secret Access Key
- Bucket: Filebase IPFS Bucket Name
- Path: Path to files to pin to IPFS
- PinName: The name for the pinned file
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.node index.js
The output will resemble the following:

If you have any questions, please join our Discord server, or send us an email at [email protected]
Last modified 5mo ago