How To Utilize Filebase with NodeJS
Learn how to utilize Filebase with NodeJS.
NodeJS is an open-source, cross-platform JavaScript runtime environment that executes JavaScript code in environments other than web browsers. It’s primarily used for traditional websites and back-end API services.
Read below to learn how to utilize Filebase with NodeJS.
Filebase would like to thank @figurestudios on Medium for the original version and publication of this tutorial guide.
mkdir hello-filebase
cd hello-filebase
This sample showcases getting buckets and uploading objects, but in this tutorial we’ll download objects as well.
require('dotenv').config();
const AWS = require('aws-sdk');
const s3 = new AWS.S3({endpoint: 'https://s3.filebase.com', signatureVersion: 'v4'});
function Upload(bucket, name) {
var params = {
Bucket: bucket,
Key: name,
ContentType: 'text/plain'
};
s3.putObject(params, function(error, data) {
if (error) {
console.error(error);
} else {
console.log('Successfully uploaded file' + name + ":" + bucket);
}
});
}
function Download(bucket, key, callback) {
var params = {
Key: key,
Bucket: bucket
};
try {
s3.getObject(params, function(error, data) {
if (error) {
console.log("Error while reading file " + key + ":" + bucket);
return callback("Error!");
} else {
console.log("Returning contents from " + key + ":" + bucket);
return callback(Buffer.from(data.Body, 'utf8').toString());
}
});
} catch (error) {
console.error(error);
return callback("Error!");
}
}
Select ‘Create Bucket’ in the top right corner to create a new bucket.

In this guide, we’re calling the bucket
filebase-IPFS
.Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.

Upload("filebase-bucket-name", "object-name");
npm install aws-sdk
npm install dotenv
AWS_ACCESS_KEY_ID=FILEBASE_ACCESS_KEY
AWS_SECRET_ACCESS_KEY=FILEBASE_SECRET_KEY
Replace the values with your
FILEBASE_ACCESS_KEY
and FILEBASE_SECRET_KEY
.node main.js
Download("filebase-bucket-name", "object-name");
If you have any questions, please join our Discord server, or send us an email at [email protected]
Last modified 5mo ago