Interview Hub
Sign in

Q13: CommonJS vs ES modules in Node?

MidNode.js 29

Answer

CommonJS uses require/module.exports; loads are synchronous at runtime (with caching). ESM uses import/export; static analysis, async loading, top-level await in ESM. Node treats .cjs/.mjs and type: module in package.json. Interop sometimes needs dynamic import() from CJS or default exports shape differences.

Having a tech or coding interview? Check 29 JavaScript & Node.js interview questions.

Source: Node.js — Modules

EditorJavaScript · local only