This Node.js application allows you to easily pine files to IPFS using the Fleek SDK.
Before you begin, make sure you have the following installed:
- NodeJs 18+
- npm (Node Package Manager)
- fleek CLI (https://docs.fleek.xyz/docs/CLI)
Follow these steps to get started with the Fleek Node.js App:
-
Clone this repository:
git clone https://github.com/fleekxyz/pin-files-to-ipfs-with-fleekSDK.git
-
Navigate to the project directory:
cd pin-files-to-ipfs-with-fleekSDK
-
Enviroment Variables duplicate and rename
.example.env
to.env
-
Install dependencies:
npm install
-
Duplicate
.example.env
, and rename to.env
-
Obtain a Personal Access Token (PAT) from Fleek. Run
fleek pat create
on your terminal, copy your PAT, and insert into your.env
file. -
Create and Obtain your ProjectID Run
fleek projects create
this will create a new project for you on fleek. Then runfleek projects list
this will list out all your projects and their corresponding project ID in your terminal. Copy your project ID. It should look like this:clrje1234567abcdedf
, and insert into your env file.
Once the application is running, follow these steps to upload a file to IPFS:
-
Ensure that the file you want to upload is in the project directory.
-
Update the
filename
in the code to match the file you want to upload:const fileContent = fs.readFileSync('<filename>'); uploadFileToIPFS('<filename>', fileContent) .then(result => { console.log('File uploaded to IPFS:', result); }) .catch(error => { console.error('Error uploading file to IPFS:', error); }).finally(()=> { process.exit(); });
-
Execute the application:
npx tsx index.ts
-
Upon successful execution, you will see a message indicating that the file has been uploaded to IPFS along with the resulting data.