commonJS
commonJS 是 nodejs 默认模块管理方式,不支持es6的模块化管理方式,但支持所有es6+语法
require 引入模块、输入 对象|函数|类
require(‘模块名’)
不指定路径: 先找系统模块-> 再从项目环境找node_modules|bower_components (依赖模块)->not found
指定路径 : 指定路径 -> not found
require(./utils).xx 按需引用
exports 导出,批量输出 都是属性
exports.自定义属性=值(any) 输出带接口 require(模块文件名)=modA modA是个模块实例{自定义属性}
module 默认输出 函数|类|对象 只能输出一次
module.exports = {自定义属性:值}
module.exports=对象/fn/class require(’…’)=modA modA 是一个fn或者是类class本身
Node.js与CommonJS模块系统
本文详细介绍了Node.js中默认的CommonJS模块系统,包括其工作原理、require与exports的使用方法,以及如何通过模块进行代码组织和复用。
852

被折叠的 条评论
为什么被折叠?



