最近在学习node,刚开始不明白为什么写node的时候,不能用import而只能用require,Node对CommonJS模块规范的实现, CommonJS模块基本上包括两个基础的部分:一个取名为exports的自由变量,它包含模块希望提供给其他模块的对象,以及模块所需要的可以用来引入和导出其它模块的函数, 所以node.js里面导出使用module.exports = 模块名
,引入的时候使用require
下面是node中使用的CommonJS的部分说明
The module.syncBuiltinESMExports() method updates all the live bindings for builtin ES Modules to match the properties of the CommonJS exports
官方地址: http://nodejs.cn/api/modules.html
commonJs的知识链接: https://www.w3cschool.cn/zobyhd/1ldb4ozt.html
原文:https://www.cnblogs.com/antyhouse/p/13278833.html