Repaso
EspaƱol

What do package.json and npm do?

Options

  1. package.json lists dependencies; npm installs them (Correct option)
  2. npm is a database in which packages are stored
  3. package.json compiles Java code for the backend
  4. node_modules is a Git branch with the packages

Answer

package.json lists the project's metadata, scripts and dependencies; npm is the tool that installs them into node_modules

Why

Node.js projects (React, build tools) use npm (Node Package Manager), like Maven for JavaScript.

package.json: name, version, dependencies (needed to run), devDependencies (build/test tools) and scripts (npm run build, npm test).

npm install downloads libraries into node_modules (do not commit it) and records exact versions in package-lock.json. Alternatives: yarn, pnpm.

Remember

package.json = manifest. npm install = download dependencies.

Key terms

Practice this question in Repaso