What is npm install and what does it do?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Node.js topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

npm install (or npm i) downloads and installs packages from the npm registry into the local node_modules/ directory. Variants: npm install (no args) — installs all dependencies listed in package.json; npm install <package> — installs a package and adds it to dependencies; npm install <package> --save-dev (or -D) — adds to devDependencies (not included in production build); npm install <package> --global (or -g) — installs globally for CLI use; npm install <package>@1.2.3 — install a specific version. npm resolves the full dependency tree, downloads packages, and generates/updates package-lock.json, which locks exact versions for reproducible installs. The node_modules/ folder should be added to .gitignore — teammates run npm install to recreate it from package.json.

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Node.js project.