npm / yarn

2025.12.06

Initialization

npmyarnDescription
npm inityarn initInteractive initialization
npm init -yyarn init -yInitialize with defaults

Package Installation

npmyarnDescription
npm installyarnInstall dependencies
npm install pkgyarn add pkgAdd package
npm install -D pkgyarn add -D pkgAdd as dev dependency
npm install -g pkgyarn global add pkgInstall globally
npm install pkg@1.0.0yarn add pkg@1.0.0Specific version
npm install pkg@latestyarn add pkg@latestInstall latest

Package Removal

npmyarnDescription
npm uninstall pkgyarn remove pkgRemove package
npm uninstall -g pkgyarn global remove pkgRemove globally

Package Update

npmyarnDescription
npm updateyarn upgradeUpdate all packages
npm update pkgyarn upgrade pkgUpdate specific package
npm outdatedyarn outdatedShow outdated packages

Information

npmyarnDescription
npm listyarn listList installed packages
npm list --depth=0yarn list --depth=0Top-level only
npm info pkgyarn info pkgPackage information
npm search keyword-Search packages
npm view pkg versionsyarn info pkg versionsAvailable versions

Script Execution

npmyarnDescription
npm run scriptyarn scriptRun script
npm startyarn startRun start script
npm testyarn testRun test script
npm run buildyarn buildRun build script
npx pkgyarn dlx pkgExecute temporarily

Cache

npmyarnDescription
npm cache clean --forceyarn cache cleanClear cache
npm cache verify-Verify cache

Lock Files

npmyarnDescription
package-lock.jsonyarn.lockLock file name
npm ciyarn install --frozen-lockfileStrict install from lock

Publishing

npmyarnDescription
npm loginyarn loginLogin to registry
npm publishyarn publishPublish package
npm unpublish pkg-Unpublish package
npm version patchyarn version --patchBump patch version
npm version minoryarn version --minorBump minor version
npm version majoryarn version --majorBump major version

Configuration

npmyarnDescription
npm config listyarn config listList config
npm config set key valueyarn config set key valueSet config
npm config get keyyarn config get keyGet config

Audit & Security

npmyarnDescription
npm audityarn auditCheck vulnerabilities
npm audit fix-Auto-fix vulnerabilities

Workspaces

npmyarnDescription
npm init -w packages/a-Initialize workspace
npm install -w a pkgyarn workspace a add pkgAdd to workspace
npm run -w a scriptyarn workspace a scriptRun in workspace
npm run --workspaces scriptyarn workspaces run scriptRun in all workspaces

Common Command Combinations

CommandDescription
rm -rf node_modules && npm installClean install
npm list --depth=0 | grep pkgSearch package
npm ls pkgShow package dependents
npm explain pkgShow detailed dependencies
npm dedupeDeduplicate packages
npm pruneRemove unused packages
← Back to list