npm Commands Cheatsheet
npm package management, scripts, npx, and yarn/pnpm equivalents
Your data never leaves the browser — all processing is done locally 0 server requests
Project Initialization
-
npm init -yCreate package.json immediately with default values
-
npm initCreate package.json interactively
-
npm create vite@latestScaffold a new Vite-based project
-
npx create-react-app 앱이름Create a new React app (CRA)
Package Installation
-
npm installInstall all dependencies listed in package.json
-
npm install 패키지명Install a package and add it to dependencies
-
npm install -D 패키지명Install a package and add it to devDependencies (build tools, etc.)
-
npm install -g 패키지명Install a package globally
-
npm install 패키지명@1.2.3Install a specific version of a package
-
npm install 패키지명@latestInstall the latest version of a package
-
npm ciInstall exact versions from package-lock.json (recommended for CI)
Package Removal & Update
-
npm uninstall 패키지명Remove a package and delete it from package.json
-
npm updateUpdate all packages within their allowed version ranges
-
npm update 패키지명Update a specific package
-
npm outdatedCheck which packages have newer versions available
Running Scripts
-
npm run 스크립트명Run a script defined in package.json scripts
-
npm startRun the start script (e.g., dev server)
-
npm run buildRun the build script (production build)
-
npm testRun the test script
-
npx 패키지명 [옵션]Run a package temporarily without installing it
Package Lookup & Info
-
npm listPrint the dependency tree for the current project
-
npm list --depth=0Show only top-level installed packages
-
npm list -g --depth=0List globally installed packages
-
npm info 패키지명Fetch package info from the npm registry
-
npm view 패키지명 versionsList all available versions of a package
Cache & Configuration
-
npm cache clean --forceForce-clear the npm cache (useful for fixing install errors)
-
npm config listPrint the current npm configuration
-
npm config set registry https://registry.npmjs.org/Reset the npm registry to the default
-
npm auditScan for security vulnerabilities
-
npm audit fixAutomatically patch fixable vulnerabilities
yarn / pnpm Equivalents
Equivalent commands when using yarn or pnpm instead of npm
-
yarn add 패키지명yarn: Install a package (equivalent to npm install <pkg>)
-
yarn add -D 패키지명yarn: Install a package as a dev dependency
-
pnpm add 패키지명pnpm: Install a package (optimized disk efficiency)
-
pnpm installpnpm: Install all dependencies
npm: package.json Is Your Project's Blueprint
npm is the standard package manager for the Node.js ecosystem. The core workflow — npm install to set up dependencies, npm run build/start to execute scripts — applies to almost every JavaScript and TypeScript project. Always commit package-lock.json so teammates install identical versions.
yarn and pnpm use the same concepts but different internals. pnpm's content-addressable store dramatically reduces disk usage across projects and speeds up installs. Monorepos benefit from npm workspaces, yarn workspaces, or pnpm workspaces.
FAQ
- What is the difference between npm install and npm ci?
- npm install reads package.json and may update package-lock.json. npm ci reads package-lock.json exactly, wipes node_modules first, and installs precisely — no lock file changes. Use npm ci in CI/CD pipelines for reproducible builds.
- Which should I use: npm, yarn, or pnpm?
- npm ships with Node.js and needs no extra setup. yarn has strong workspaces support. pnpm uses hard links to save disk space and is significantly faster. Follow your team's choice; for a new project, pnpm is a great default.
- What is the difference between npx and npm run?
- npm run executes scripts defined in the scripts field of package.json. npx runs a package's binary from node_modules or downloads it temporarily from the registry. npx is ideal for one-off tools like create-react-app.