Language concepts

CommonJS module.exports

Try the free JavaScript compiler

Node CommonJS export value, returned when the module is loaded by require. Reassigning the local exports alias does not replace module.exports. Not ECMAScript module syntax. Multi-file example: save each listed file separately, then run the entry file with Node.js. See the packaged fixture for the original files.

Formal Syntax & Structure

javascript syntaxjavascript
module.exports = value;

Working Example

Example Snippetjavascript
// File: calc.cjsmodule.exports = n => n * 4;
// File: main.cjsconst multiply = require("./calc.cjs");console.log(multiply(3));
JavaScript Reference