Can't connect to IPFS API

Hello everyone,
I’m developing a dapp using node.js and IPFS, where the user can select a file from a web page and upload it to IPFS. My problem is that I can’t connect my app to the IPFS API, even though the daemon is running correctly on my machine.
Every command from cli works correctly as well, but if I try to replicate, for instance, the “add” command on my app, it doesn’t work.
The error I get when I use the create() command is:
FetchError: request to http://localhost:5001/api/v0/version failed, reason: connect ECONNREFUSED ::1:5001

I’ve already allowed CORS requests but nothing changed.

Could someone help me, please? I really do not know what to do anymore

sounds like your node isn’t running or that your firewall is blocking it’s access.

The node is running correctly (I can access it by and I can upload files with cli commands as well). I’ve already tried to turn off Windows firewall, use another network but nothing changed.
The code I’m using is the following:

var ipfs = ipfsAPI(‘localhost’, ‘5001’, {protocol: ‘http’});

console.log(‘Your IPFS node is ready.’);
ipfs.version((err, version) => {
if(err) {
console.error(‘Error getting the IPFS version’, err);
console.log('version: ',version.version)
Previously I tried with const ipfs = await create(); but with the same result.

I don’t think that it but just because that different, can you try instead of localhost in your ipfsAPI ?

I can’t believe it, I’ve been stuck on that problem for 4 days and the solution was that simple.
Thank you very much for your help :slight_smile:

1 Like