1# Old Way: CommonJS (CJS)
2Keywords: require() to import, module.exports or exports to export.
3Loading: Synchronous (code pauses until module is loaded).
4Usage: Default for .js files unless package.json says otherwise. Use .cjs extension for explicit CJS.
5
6# New Way: Standard JavaScript module system (also used in browsers) ECMAScript Modules (ESM):
7Keywords: import to import, export to export.
8Loading: Asynchronous (more flexible, allows features like top-level await).
9Usage: Activated by setting "type": "module" in package.json for .js files, or by using the .mjs extension.
10
11## Notes
12- Node.js needs to know if a file is CJS or ESM to load it correctly.
13- Mixing them requires careful configuration (in package.json and tsconfig.json if using TypeScript).
14- Tools like ts-node, tsx, bundlers, etc., need to understand which system you're using.
15- Recommendation: Use ESM ("type": "module") for modern Node.js projects.
16
Created on 4/21/2025