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 my application, IPFS gets the content and adds it with .add() method, entire on 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. 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:
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 code is 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?