intermediate

Modules and packages

Node package loading, ESM/CommonJS interop, resolution, exports maps, npm scripts, and runtime package boundaries.

Module and package interviews test how Node loads code at runtime and how you publish stable package boundaries. Expect ESM vs CommonJS interop, resolution rules, exports maps, and npm scripts as operational contracts.

Subtopics: ESM vs CommonJS, module resolution, package exports, and npm scripts.

On interviews: explain why a require/import fails in a mixed codebase, how exports maps hide internals, and what lockfiles protect in CI and production.

Common pitfalls: assuming ESM and CJS are drop-in interchangeable, deep imports that break on upgrades, and scripts that hide environment assumptions.

The trade-off is balancing simplicity, performance, safety, and operability — name which axis you optimized and what cost you accepted.

Checklist:

  • Compare static ESM imports with runtime require.
  • Trace bare specifier and node_modules resolution.
  • Design exports maps as a public API contract.
  • Use scripts for repeatable dev, test, and build flows.