Home › Node.js Tutorial › Node.js modules
Node.js modules
Split code into reusable files.
In CommonJS, require loads a module and module.exports shares values from a file. Newer code can use import and export with the .mjs extension.
Example code
const math = { add: function (a, b) { return a + b; } };
module.exports = math;
console.log(typeof module.exports, math.add(2, 3));