每次我尝试用Nodejs和IPFS/OrbitDB构建一个Dapp时,我试着启动我的应用程序--我得到了错误:
this.node =新IPFS({ ^)
TypeError: IPFS不是构造函数
这是我的基本代码,没有一个特定的群:
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应用程序上尝试了它,在那里,当我添加了一个要连接的特定群时,我也遇到了同样的错误。
我非常感谢你的帮助,谢谢你提前给我时间。
亲切的问候
贝尼
发布于 2020-04-21 15:09:19
我现在是这样做的:
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)
https://stackoverflow.com/questions/61065691
复制相似问题