
If you’re building with JavaScript or Node.js, you’re already using npm (Node Package Manager). It’s more than just npm install
— npm has a rich set of commands that every developer (from beginner to pro) should know.
This guide organizes all npm commands into categories with purpose, usage, and examples — your one-stop reference.
🚀 Project Initialization
Purpose: Start new projects, set up package metadata.
npm init //Create a package.json interactively
npm init -y //Quick init with defaults
📦 Installing Dependencies
Purpose: Add packages to your project.
npm install <package_name> // install dependency
npm install <package_name> --save-dev // Install dev dependency
npm install -g <package_name> //install package globally
npm install <package_name>@4.17.21 // Install specific version
npm ci // Clean install (CI/CD safe)
♻️ Updating & Removing Packages
Purpose: Keep dependencies fresh and clean.
npm update <package_name> // Update a package
npm outdated // Check outdated package
npm uninstall <package_name> // Uninstall a package
npm dedupe // Remove duplicate packages
▶️ Running Scripts
Purpose: Automate tasks via package.json
.
npm run build // Run a script
npm start // runs start
npm test // runs test
npm restart // restart lifecycle scripts
npm stop // stop lifecycle scripts
🔍 Dependency Management
Purpose: Inspect and manage installed packages.
npm list --depth=0 // List dependencies
npm why react // Show why a package is installed
npm prune // Prune unused packages
npm fund // View funding info
🔒 Security & Diagnostics
Purpose: Keep your project secure and healthy.
npm audit // Audit for vulnerabilities
npm audit fix // Run environment diagnostics
npm doctor // Run environment diagnostics
npm ping // Check registry connection
⚡ Cache & Config
Purpose: Manage npm cache and settings.
npm cache clean --force Clear cache
npm cache verify // Verify cache
npm config list // View config
npm config set registry https://registry.npmjs.org/ // Change registry (for private repos)
🚀 Publishing & Versioning
Purpose: Share packages with the world.
npm login
npm logout
npm publish // Publish package
npm unpublish <package_name>@1.0.0 // Unpublish (careful!)
npm version patch // 1.0.0 → 1.0.1
npm version minor // 1.0.0 → 1.1.0
npm version major // 1.0.0 → 2.0.0
npm dist-tag add my-package@2.0.0 beta // Manage tags
🧰 Advanced/Pro-Level Commands
Purpose: Deep package, org, and registry management.
npm access grant read-write my-org:devs my-package // Access control
npm deprecate my-package@"<1.0.0" "No longer supported" // Deprecate a version
npm token list // Manage tokens
npm team create my-org:devs // Manage orgs/teams
npm explore lodash -- npm run test // Explore/edit installed package
npm edit lodash
npm repo lodash // Open repo/bugs page
npm bugs react
npm query ".dependencies[?name=='express']" // Query dependencies
⚡ Bonus: NPX
Purpose: Run commands without global installs.
npx cowsay "Hello Dev!"
npx create-react-app my-app
✅ Final Thoughts
npm isn’t just a package installer — it’s a complete package management system.
- Use basic commands to install and run.
- Use advanced commands for diagnostics, publishing, and team workflows.
- Combine with npx for instant execution.
With these commands, you’re ready to manage projects like a professional.