节点js文件中的多个module.exports

Multiple module.exports in a node js file

当一个文件有多个 module.exports 并且另一个文件需要它时,Nodejs 引擎如何决定? 如何计算最终关闭数?

它使用模块执行完成后 module.exports 的值:

module.exports = { foo: 'bar' };
module.exports = { a: 17.8 };    // overwrite "module.exports"
module.exports = 5;              // and again 
module.exports = { b: 123 };     // and again

现在,当您需要该模块时,您将获得 { b: 123 }

module.exports 不是魔法关键字,它只是一个变量,您可以设置它来告诉 NodeJS 应该导出什么。