Search code examples
javascriptipfsjs-ipfs

"POST http://localhost:9090/spawn ERR_CONNECTION_REFUSED" error while spawning an IPFS daemon using ipfsd-ctl


I'm trying to Spawn an IPFS daemon from the Browser using the provided remote endpoint using the ipfsd-ctl library.

This is the link I'm referring

// Start a remote disposable node, and get access to the api
// print the node id, and stop the temporary daemon

const Ctl = require('ipfsd-ctl')

const port = 9090
const server = Ctl.createServer(port, {
    ipfsModule: require('ipfs'),
    ipfsHttpModule: require('ipfs-http-client')
},
{
    js: {
        ipfsBin: 'path/js/ipfs/bin'
    },
    go: {
        ipfsBin: 'path/go/ipfs/bin'
    },
})
const factory = Ctl.createFactory({
    ipfsHttpModule: require('ipfs-http-client'),
    remote: true,
    endpoint: `http://localhost:${port}` // or you can set process.env.IPFSD_CTL_SERVER to http://localhost:9090
})

await server.start()
const ipfsd = await factory.spawn()
const id = await ipfsd.api.id()

console.log(id)

await ipfsd.stop()
await server.stop()

It shows a "Server not implemented in the browser" warning and "POST http://localhost:9090/spawn net::ERR_CONNECTION_REFUSED" error


Solution

  • Ctl.createServer starts an HTTP Server that Ctl.createFactory will connect to. As the warning says "Server not implemented in the browser", you need to run it in nodejs and from the browser use Ctl.createFactory to interact with it.