CommonJS is a module architecture, where each file is treat as a individual module. Which can be imported and being used in any files by just requiring it.
In the Node.js module system, each file is treated as a separate module. For example, consider a file named foo.js:
const circle = require('./circle.js');
console.log(`The area of a circle of radius 4 is ${circle.area(4)}`);On the first line, foo.js loads the module circle.js that is in the same directory as foo.js.
Here are the contents of circle.js:
const { PI } = Math;
exports.area = (r) => PI * r ** 2;
exports.circumference = (r) => 2 * PI * r;

0 Comments