javascriptnode.jsipfsorbitdb

TypeError: IPFS is not a constructor


I'm trying to use Orbit-DB, So I follow the guide. But at the Create a database step, I get an error:

const ipfs = new IPFS()
             ^

TypeError: IPFS is not a constructor

Here is my full code:

const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')

// Create IPFS instance
const ipfs = new IPFS()
ipfs.on('ready', async () => {
  const orbitdb = await OrbitDB.createInstance(ipfs)
  const db = await orbitdb.docs('opews-db-test1')
  const address = db.address
})

I checked that there was no error in the require() with a console.log(), but it seems not. So I don't know how to fix that...


Solution

  • IPFS has changed the way you construct an IPFS node, can you try this code:

    const IPFS = require('ipfs')
    const OrbitDB = require('orbit-db')
    
    async function main() {
      const ipfs = await IPFS.create();
      const orbitdb = await OrbitDB.createInstance(ipfs);
      const db = await orbitdb.docs('opews-db-test1');
      const address = db.address;
    }
    
    main();