CommonJS

CommonJS 模块规范的导入导出方式与运行机制说明

#status / growing #type / concept

[!info] related notes

CommonJS

在 Node.js 里,早期更常见的是 CommonJS

导出:

// math.js
function add(a, b) {
  return a + b;
}

module.exports = {
  add
};

导入:

const math = require("./math");

console.log(math.add(1, 2));
创建于 2026/3/15 更新于 2026/4/9