The exports alias
In a CommonJS module, exports initially refers to the same object as module.exports. Adding properties through exports works while the reference is shared. Reassigning the local exports variable does not replace the actual exported value.
Local practice: The proposed teaching runtime is Node.js 26.13.1 LTS. These original offline examples were executed on Node.js 22.16.0 (Linux x64); execution on the proposed baseline and in ByteMind is not yet verified. No npm dependencies are required. Use a fresh practice directory. Code blocks are static, not a browser-based Node runner.
Attach a property through the alias
const config = require("./config.cjs");console.log(config.label);In the directory containing the files above, run:
node main.cjsExpected standard output:
CatalogExpected exit status: 0.
How it works
The CommonJS wrapper supplies module and exports to the file. At initialization, exports is a convenient reference to the export object. exports.label = "..." changes that object. exports = { ... } points the local variable at a new object; the module still exposes the original object. To replace the exposed value completely, assign module.exports. This distinction is ordinary JavaScript reference behavior, not a special syntax rule for property assignment.
Compare rebinding and replacing the export
const bad = require("./bad.cjs");const good = require("./good.cjs");console.log(bad.label);console.log(good.label);In the directory containing the files above, run:
node main.cjsExpected standard output:
undefinedCatalogExpected exit status: 0.
Common mistake
If you replace module.exports, the old exports alias may still refer to the old object. Avoid mixing styles after replacement; choose property assignments or an explicit final module.exports assignment. The incorrect fixture is valid JavaScript but fails the intended export contract.
Try it yourself
Export a function called formatTitle as a property using exports.formatTitle. Then rewrite the module to export the function directly via module.exports. Adjust the consumer to match each interface.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
The exports alias — knowledge check
Check your understanding of the exports alias.
At CommonJS initialization, what is exports?
What does `exports = { label: "Catalog" }` alone expose?
Which expression replaces the actual exported value?