npm
Node Package Manager
The package manager for Node.js. Installs JavaScript libraries and manages dependencies. The world's largest package registry.
Node Package Manager
The package manager for Node.js. Installs JavaScript libraries and manages dependencies. The world's largest package registry.
npm (Node Package Manager) is the default package manager for Node.js and the world's largest software registry. Since its release in 2010, more than 2 million packages have been registered, and weekly downloads reach into the billions.
Its core features include installing/removing packages, managing dependencies, running scripts, and publishing packages. Project metadata and dependencies are defined in package.json, and exact versions are pinned with package-lock.json. It follows Semantic Versioning (major.minor.patch).
Packages are installed in the node_modules folder, and the dependency tree is hoisted flat. Since npm 7, workspaces support monorepos, and npm audit checks for security vulnerabilities. With npx, you can run packages without installing them.
In practice, CI uses npm ci (clean install) for lock-file-based installation, --save-exact to pin versions, and .npmrc to configure private registries. npm run standardizes build/test scripts.
# ํ๋ก์ ํธ ์ด๊ธฐํ
npm init -y
# ํจํค์ง ์ค์น
npm install express # dependencies
npm install -D jest # devDependencies
npm install -g typescript # ๊ธ๋ก๋ฒ ์ค์น
npm install react@18.2.0 # ํน์ ๋ฒ์
npm install --save-exact lodash # ์ ํํ ๋ฒ์ ๊ณ ์ (^ ์์ด)
# CI ํ๊ฒฝ ์ค์น (package-lock.json ๊ธฐ๋ฐ)
npm ci
# ํจํค์ง ์ ๋ณด ๋ฐ ๊ฒ์
npm view express versions # ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฒ์ ํ์ธ
npm outdated # ์
๋ฐ์ดํธ ๊ฐ๋ฅํ ํจํค์ง
npm ls --depth=0 # ์ค์น๋ ํจํค์ง ๋ชฉ๋ก
# ๋ณด์ ๊ฒ์ฌ
npm audit # ์ทจ์ฝ์ ๊ฒ์ฌ
npm audit fix # ์๋ ์์
npm audit fix --force # ๋ฉ์ด์ ์
๋ฐ์ดํธ ํฌํจ ์์
# ์คํฌ๋ฆฝํธ ์คํ (package.json scripts)
npm run build
npm run test
npm start # npm run start ๋จ์ถํ
npm run dev -- --port 3001 # ์ธ์ ์ ๋ฌ
# ํจํค์ง ๋ฐฐํฌ
npm login
npm version patch # ๋ฒ์ ์ฆ๊ฐ (1.0.0 -> 1.0.1)
npm publish
npm deprecate my-pkg "Use new-pkg instead"
# ์บ์ ๊ด๋ฆฌ
npm cache clean --force
npm cache verify
Senior: "npm audit found 3 critical vulnerabilities. Have you looked into them?"
Junior: "I checked, and they're in development dependencies, so there's no impact on production. I'll still include the update in the next sprint."
Interviewer: "What is the difference between npm install and npm ci?"
Candidate: "npm install installs based on package.json and can update the lock file, whereas npm ci uses package-lock.json as is and completely deletes node_modules before reinstalling. In CI environments, we use npm ci for reproducibility."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Reviewer: "The package-lock.json changes are large. Did you run npm install again?"
Developer: "Yes, I deleted node_modules locally and reinstalled, and that changed it. They are updates within the version ranges."