How To Utilize Filebase with NodeJS
Learn how to utilize Filebase with NodeJS.
What is NodeJS?
1. Open a Node.js command prompt. To create a folder to store both our files and our code, run the command:
2. Then navigate into our new folder with the command:
3. Open Visual Studio Code, or any other IDE of your choice and create a new JavaScript file called main.js that is stored in your hello-filebase folder.
main.js that is stored in your hello-filebase folder.4. This tutorial will build off of the Filebase NodeJS sample repository.
5. In your new main.js file, add the following lines to import the dependencies for this project:
6. Then, add a function to upload objects:
7. We’ll also add a second function for downloading objects with the following code:
8. Now let's make a Filebase bucket. To do this, navigate to console.filebase.com.
9. Select ‘Buckets’ from the left side bar menu, or navigate to console.filebase.com/buckets.

10. Enter a bucket name and choose the IPFS storage network to create the bucket.

11. Now at the end of our main.js code, add the following line, replacing the filebase-bucket-name with your bucket name, and object-name with the file name for your object to be uploaded.
main.js code, add the following line, replacing the filebase-bucket-name with your bucket name, and object-name with the file name for your object to be uploaded.12. In the NodeJS Command Prompt, install the following dependencies:
13. Create a new file, either in your IDE or from the command line, called .env with the following content:
.env with the following content:14. In the NodeJS Command Prompt, we’re ready to run our code with the following command:
15. The uploaded object will now be reflected in your Filebase bucket.
16. Then, you can download the object. To do this, replace the last line of your main.js file that calls the Upload function with the following line:
main.js file that calls the Upload function with the following line:17. Then run the node main.js command again. This will download the object to your local directory.
Last updated