Modules, ESM & Package Management Interview Questions (Node.js)
10 Modules, ESM & Package Management questions from the Node.js track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Junior
Compare CommonJS (CJS) and ES Modules (ESM) in Node.js. How does the runtime handle them?
CJS is synchronous and uses require() at runtime, while ESM uses static import/export and resolves the dependency graph asynchronously before execution.
Read the full explanation - Senior
What is the 'exports' field in package.json, and how does it improve on the older 'main' field?
It lets you define a package's official entry points, control access to internal files, and select different outputs for CJS and ESM.
Read the full explanation - Mid-level
How does Node.js handle circular dependencies between CJS and ESM?
CJS returns an incomplete exports object while modules load synchronously, whereas ESM links live bindings, but reading an uninitialized variable can throw a ReferenceError.
Read the full explanation - Junior
What is the difference between npm install and npm ci, and why is package-lock.json important?
npm ci removes node_modules and installs the exact versions specified in package-lock.json for a reproducible build, while npm install may update packages within their SemVer ranges.
Read the full explanation - Mid-level
How do npm/pnpm Workspaces manage monorepos, and what are their benefits?
They let you manage multiple packages in one repository, share dependencies, and link local packages to each other as symlinks without publishing them.
Read the full explanation - Senior
What is the Dual Package Hazard when publishing a library that supports both CJS and ESM in Node.js?
It occurs when the same application imports two different instances of a library, duplicating singletons and breaking instanceof checks.
Read the full explanation - Junior
How do you use Node.js's built-in test runner (node:test) without external libraries?
The node:test module and node:assert provide a fast, built-in test environment with test, describe, and it functions.
Read the full explanation - Junior
What do the ^ and ~ symbols mean in package.json, and how do they differ from an exact version?
^ permits compatible Minor and Patch updates, while ~ limits updates to Patch versions; omitting a symbol pins the exact version.
Read the full explanation - Junior
Why is the node: prefix useful when importing built-in modules such as node:fs and node:path?
It clearly identifies a module as built in, prevents dependency confusion, and speeds up module resolution.
Read the full explanation - Mid-level
How does modern Node.js support running TypeScript files directly with Type Stripping?
Type Stripping is enabled by default starting in Node.js 22.18 and 23.6, so you can run a TypeScript file directly with node app.ts without build tools; older versions require the --experimental-strip-types flag.
Read the full explanation