Question presented to candidate: "A new teammate asks what package.json actually does versus what npm does. How do you explain the division of responsibility between the two?"
What a strong answer should cover:
package.jsonis a declarative manifest: the project's name, version, entry point, scripts, and — most importantly for this question — its dependencies, each expressed as a semver range (e.g.^4.17.20), not a single pinned version.npm(Node Package Manager) is the tool that reads that manifest and acts on it: resolving each dependency's range to an actual version, downloading it from the registry, laying outnode_modules, and running the scripts declared inpackage.json's"scripts"field vianpm run <name>.- 📌 The precise distinction worth stating:
package.jsondescribes intent (what range of versions is acceptable); the actual, exact versions that were resolved and installed are recorded separately, inpackage-lock.json— covered in its own dedicated question. npmis also the interface to the npm registry, the public (or private) package repositorynpm install <package>downloads from —package.jsonhas no knowledge of the registry itself, only of the range it wants satisfied from it."scripts"inpackage.jsonis a common source of confusion: it is not a build system, just a named-command shortcut table (npm run build→ whatever shell command"build"maps to) that also gets the project's localnode_modules/.binadded toPATHfor that command.- A precise answer also names that npm is one of several compatible package managers (Yarn, pnpm) that all consume the same
package.jsonformat — the manifest format is a de facto ecosystem standard, not npm-proprietary, even though npm is the default bundled with Node.
Clarifying questions expected:
- "Is the question about the file format, the CLI tool, or the registry?" — these are three distinct things commonly bundled under "npm."
- "Does the team use npm specifically, or Yarn/pnpm against the same package.json?" — decides how much of the answer should be npm-CLI-specific versus format-general.
Code / implementation expected: Optional — showing a real, freshly generated package.json after npm init and npm install is a clean way to ground the answer in something concrete rather than a description.