我想module.exports.myInstance
从其他文件中访问一个函数,如下所示。
// a.js
const func = async function () {
...
module.exports.myInstance = ...;
}
func();
// b.js
const module = require("a.js").myInstance;
console.log(module);
我需要放入module.exports
一个函数内部,因为我有一些东西可以使用 await 来获取myInstance
。我试过这个并测试过,但我有undefined
when console.log(module)
. 这不是一种可能的格式吗?如果是,我应该怎么做才能完成这项工作?