Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IPFS不是构造函数:Nodejs-IPFS/OrbitDB聊天室_Javascript_Node.js_Publish Subscribe_Ipfs_Orbitdb - Fatal编程技术网

Javascript IPFS不是构造函数:Nodejs-IPFS/OrbitDB聊天室

Javascript IPFS不是构造函数:Nodejs-IPFS/OrbitDB聊天室,javascript,node.js,publish-subscribe,ipfs,orbitdb,Javascript,Node.js,Publish Subscribe,Ipfs,Orbitdb,我正在尝试使用Nodejs和IPFS/OrbitDB构建一个Dapp每次我尝试启动我的应用程序时,都会出现以下错误: this.node=新的IPF({ ^ 类型错误:IPFS不是构造函数 这是我没有特定Swarm的基本代码: const Ipfs = require('ipfs'); const OrbitDB = require('orbit-db'); class chatroom { constructor(IPFS, OrbitDB) { this.Orbit

我正在尝试使用Nodejs和IPFS/OrbitDB构建一个Dapp每次我尝试启动我的应用程序时,都会出现以下错误:

this.node=新的IPF({ ^

类型错误:IPFS不是构造函数

这是我没有特定Swarm的基本代码:

const Ipfs = require('ipfs');
const OrbitDB = require('orbit-db');

class chatroom {
    constructor(IPFS, OrbitDB) {
        this.OrbitDB = OrbitDB;
        this.node = new IPFS({
            preload: {enable: false},
            repo: "./ipfs",
            EXPERIMENTAL: {pubsub: true},
            config: {
                Bootstrap: [],
                Addresses: {Swarm: []}
            }
        });
        this.node.on("error", (e) => {throw (e)});
        this.node.on("ready", this._init.bind(this));
    }
    async _init(){
        this.orbitdb = await this.OrbitDB.createInstance(this.node);
        this.onready();
    }
}

module.exports = exports = new chatroom(Ipfs, OrbitDB);
我正在运行以下版本的IPFS:ipfs@0.42.0

我也在一个空的Nodejs应用程序上尝试了它,当我添加了一个特定的Swarm来连接时,我也遇到了同样的错误

我非常感谢您的帮助,谢谢您提前抽出时间

问候


贝尼

我现在是这样做的:

const IPFS = require('ipfs');

async function createNode() {
        let node = await IPFS.create(
            {
                repo: (() => `repo-${Math.random()}`)(),
                    "Addresses": {
                        "Swarm": [
                            "/ip4/0.0.0.0/tcp/4001"
                        ],
                        "API": "/ip4/127.0.0.1/tcp/5001",
                        "Gateway": "/ip4/127.0.0.1/tcp/8080"
                    }
            }
            );
        try {
            await node.start();
            console.log('Node started!');
        } catch (error) {
            console.error('Node failed to start!', error);
        }
    }

(thx@Eugene)

试试这个。node=wait IPFS.create()