What is the difference between CommonJS and ES Modules?
Two module systems for sharing code between files.
CommonJS — Node's original: require / module.exports. Synchronous, runtime-loaded.
ES Modules — the standard: import / export. Static, async, browser-compatible.
Tree shaking — only ESM's static structure allows unused-code removal.
Default today: ES Modules; CommonJS persists in legacy Node code.
CJS = require (sync, dynamic, Node.js). ESM = import (async, static, standard). ESM enables tree shaking (static analysis).
Node.js supports both; browsers support only ESM. ESM is recommended for new projects.