首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IPFS不是构造函数: Nodejs /OrbitDB聊天室

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

Stack Overflow用户
提问于 2020-04-06 17:40:57
回答 1查看 601关注 0票数 1

每次我尝试用Nodejs和IPFS/OrbitDB构建一个Dapp时,我试着启动我的应用程序--我得到了错误:

this.node =新IPFS({ ^)

TypeError: IPFS不是构造函数

这是我的基本代码,没有一个特定的群:

代码语言:javascript
复制
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应用程序上尝试了它,在那里,当我添加了一个要连接的特定群时,我也遇到了同样的错误。

我非常感谢你的帮助,谢谢你提前给我时间。

亲切的问候

贝尼

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-21 15:09:19

我现在是这样做的:

代码语言:javascript
复制
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)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61065691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档