【发布时间】:2021-02-01 15:39:21
【问题描述】:
上下文:
我有 3 个文件,parent.js、child1.js 和 child2.js
parent.js
let child1 = require("./child1.js")
let child2 = require("./child2.js")
let key = "*****"
child1.start(key)
child2.start();
child1.js
let key = false;
module.exports = {
action: async() => {
return someApi.get(key);
},
start: async(_key) => {
key = key;
}
}
child2.js
module.exports = {
action: async() => {
let res = await child1.action()
...
},
start: async() => {
// startup actions
}
}
问题
我需要在child2 中从child1 运行一个函数,但我不能使用require,因为只能有一个child1 的实例
有人知道解决办法吗?谢谢
【问题讨论】:
标签: javascript node.js node-modules server-side