16 December 2024
·

NPM Package Management and Troubleshooting Commands

Installation & Dependencies

  • Install dependencies from package.json npm install
  • Install a package in development dependencies npm install package-name --save-dev
  • Remove a package npm uninstall package-name

Updates & Versions

  • Update all packages to their latest version npm update
  • Update a package to its latest version npm install package-name@latest
  • Update all packages to their latest version npx npm-check-updates -u
  • List available updates npm outdated
  • Check for outdated global packages npm outdated -g

Package Information

  • List dependencies of a package npm list package-name
  • Show installed version of a package npm list package-name
  • Explain why a package is installed npm why package-name

System & Configuration

  • Show NPM configuration npm config list
  • Show environment details (useful for debugging) npm doctor

Scripts

  • List all available npm scripts npm run
  • Run a specific script from package.json npm run script-name

Maintenance & Cleanup

  • Audit security vulnerabilities npm audit
  • Check dependencies status npx npm-check
  • Clean unused dependencies npm prune
  • Clear NPM cache forcefully npm cache clean --force