javascript - IPFS 不是构造函数:Nodejs - IPFS/OrbitDB 聊天室
问题描述
我每次都尝试使用 Nodejs 和 IPFS/OrbitDB 构建 Dapp,但我尝试启动我的应用程序时出现错误:
this.node = 新 IPFS({ ^
TypeError: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);
}
}
(谢谢@尤金)
推荐阅读
- php - 合并两个 Json Object PHP(结构不同)
- excel - 来自多列和多行的参考值
- amazon-web-services - Kubernetes Bridge VSCODE 未连接到 AWS EKS 中的依赖项
- identityserver4 - 身份服务器 4 错误 400 并将我重定向到 signin-oidc
- c++ - 如何编写一个引用“char *”或“const char*”的 C++ 函数?
- python - 高效序列化多个需要进行 REST 调用的对象
- android-jetpack-compose - LazyColumn 中的列堆叠/折叠成一列
- reactjs - 映射放大 Storage.get()
- linux - 删除可变长度字符串的一部分并将其存储在新变量中
- html - 包装和高度增加输入 React CSS