Beginner Node.js Interview QuestionsBeginnerConcept
Node.js · Question 15
What is npm and how does it work with Node.js?
Direct answer
npm (Node Package Manager) installs JavaScript packages into node_modules, records semver ranges in package.json, and runs scripts — it ships with Node and powers the largest open-source registry for server and tooling dependencies.
npm is both a CLI tool and a registry. Monorepos like AceDevHub use npm workspaces so apps/api and apps/web share lockfile integrity from the repo root.
| Command | Purpose |
|---|---|
| npm install | Install deps from package-lock.json |
| npm install fastify | Add runtime dependency |
| npm install -D vitest | Add devDependency |
| npm run dev | Execute scripts.dev from package.json |
| npm ci | Clean install for CI — fails if lock out of sync |
- node_modules — nested dependency tree; lockfile pins exact versions for reproducible builds.
- semver — ^1.2.3 allows minor/patch; exact pins for critical prod (Q41).
- Alternatives — pnpm (content-addressable), yarn — same registry, different install strategy.
package.json-snippet.json
{
"name": "@acedevhub/api",
"scripts": {
"dev": "tsx watch src/index.ts",
"content:import:interviews": "tsx src/scripts/import-content-interviews.ts"
},
"dependencies": {
"fastify": "^5.0.0",
"pg": "^8.13.0"
},
"devDependencies": {
"tsx": "^4.19.0"
}
}