InterviewHubPRO
Section Overview
Q16

Question 16 of 60

Part 2: Runtime Internals, Libuv & The Event Loop (6 - 20)

27%
Node.js & Libuv•Part 2: Runtime Internals, Libuv & The Event Loop (6 - 20)

CommonJS (`require`) vs ES Modules (`import`) resolution.

In Simple Words:

  • CommonJS: Synchronous, dynamic (require() can be placed inside conditionals), loads and executes the script immediately, caches exports in require.cache.
  • ES Modules: Asynchronous, static analysis at parse-time, supports top-level await, and handles cyclic dependencies via live bindings.
javascript
// Dynamic import in ES Modules:
if (process.env.FEATURE_FLAG) {
  const { specialFeature } = await import('./special.mjs');
  specialFeature();
}