Q2: What is the difference between CommonJS and ES Modules in Node.js?
CommonJS uses require() and module.exports synchronously at runtime. ES Modules use import and export statements parsed asynchronously at compile time.
Key Takeaways
- CommonJS loads modules synchronously using
require(). - ES Modules load modules using
import/exportsyntax.
Knowledge Check
Which file extension forces Node.js to treat a file as an ES Module by default?