I work with JavaScript and Browserify tool in Windows 10. With Browserify, One can require NodeJS modules on browser side. I required ipfs module for my JavaScript code in a .js file then browserfied that. In my application, IPFS gets the content and adds it with .add() method in browser side. After that, It gives me the related CID. I try to get the main content from server side via NodeJS. So, I try .cat() method on a .js file and run NodeJS by PowerShell. Problem is here. By this way, No content returned to me. I don’t know why.
The JavaScript code that browserified by Browserify:
const IPFS=require(“ipfs”);
.
.
.
const peer=await IPFS.create({host:“localhost”,port:5001,protocol:“http”});
peer.add().then(function(data){
window.alert(data.path)";
});
I copied the alerted result and pasted that on .cat() method that is below:
async function getFromIPFS(){
const peer=await IPFS.create({host:“localhost”,port:5001,protocol:“http”});
const flow=peer.cat();
let mainContent="";
for await(const chunk of flow){
mainContent+=chunk.toString();
}
console.log(mainContent);
}
This function called in NodeJS. When I run the NodeJS, The below result emerges on PowerShell:
As you can see, No content returned. What is the problem? How can fix it?