https://nodejs.org/docs/latest-v10.x/api/modules.html#modules_exports_shortcut
foo.js
//
const circle = require('./circle.js');
console.log(The area of a circle of radius 4 is ${circle.area(4)}
);
//circle.js const { PI } = Math;
module.exports.area = (r) => PI * r ** 2; // the module can be ignored here
module.exports.circumference = (r) => 2 * PI * r;
//bar.js
const Square = require('./square.js');
const mySquare = new Square(2);
console.log(The area of mySquare is ${mySquare.area()}
);
//square.js // assigning to exports will not modify module, must use module.exports // the module can not be ignored here module.exports = class Square { constructor(width) { this.width = width; }
area() {
return this.width ** 2;
}
};