What is the difference between CommonJS (require) and ES Modules (import) in Node.js?

Node.js Developer Medium

Node.js Developer — Medium

What is the difference between CommonJS (require) and ES Modules (import) in Node.js?

Key points

  • CommonJS is synchronous and uses require/module.exports
  • ES Modules support import/export, static analysis, and tree shaking
  • ES Modules require .mjs extension or type:module in package.json
  • ES Modules are not limited to the browser

Ready to go further?

Related questions