Skip to main content

Top 10 Npm Commands Every Developer Must Know

· 4 min read
Sivabharathy

Discover the top 10 npm commands every developer should know, with real-world examples and tips. Learn how to manage dependencies, run scripts, improve security, and streamline workflows in your Node.js projects.

If you're building JavaScript or Node.js projects, mastering npm (Node Package Manager) is non-negotiable. It’s not just about installing packages—npm is a powerful CLI tool that can streamline your workflow, manage dependencies, and even automate development tasks.

In this post, we’ll cover the top 10 npm commands every developer must know—along with real-world use cases to help you become more productive.


1. npm init

🧠 What it does:

Initializes a new Node.js project by creating a package.json file.

💡 Real-world example:

npm init

You’re starting a new CLI tool or backend service. This sets up the metadata like name, version, author, and dependencies.

⚡ Tip:

Use npm init -y to skip the prompts and accept default values.


2. npm install / npm i

🧠 What it does:

Installs all dependencies listed in package.json OR installs a specific package.

💡 Real-world examples:

npm install            # install everything from package.json
npm install express # install a specific package
npm i axios # shorthand for install

Perfect when you clone a repo and need to get all dependencies up and running.


3. npm install --save-dev

🧠 What it does:

Installs a package as a development dependency (e.g., for testing or building).

💡 Real-world example:

npm install --save-dev jest

Used for packages like eslint, jest, webpack, which are only needed during development.


4. npm uninstall

🧠 What it does:

Removes a package from node_modules and updates package.json.

💡 Real-world example:

npm uninstall lodash

When a package is no longer needed or replaced by a better one.


5. npm update

🧠 What it does:

Updates packages to the latest allowed versions based on your package.json constraints.

💡 Real-world example:

npm update

Used periodically to keep dependencies up to date without breaking semver constraints.


6. npm outdated

🧠 What it does:

Lists all outdated packages in your project.

💡 Real-world example:

npm outdated

Use this before updating dependencies, especially when debugging or preparing for production deployment.


7. npm audit + npm audit fix

🧠 What it does:

Scans for known security vulnerabilities in your dependencies.

💡 Real-world example:

npm audit
npm audit fix

You run this in CI or before deployment to make sure you’re not shipping security issues.


8. npm run <script-name>

🧠 What it does:

Runs custom scripts defined in your package.json.

💡 Real-world example:

"scripts": {
"start": "node index.js",
"test": "jest"
}
npm run start
npm run test

You use this to create consistent, reusable commands for build, test, lint, deploy, etc.


9. npm ci

🧠 What it does:

Installs dependencies using the exact versions from package-lock.json. It’s faster and more reliable than npm install in CI environments.

💡 Real-world example:

npm ci

Used in GitHub Actions, Docker builds, and production pipelines for reproducible installs.


10. npx

🧠 What it does:

Executes a package without installing it globally.

💡 Real-world example:

npx create-react-app my-app

Great for running CLI tools like create-react-app, eslint, prettier, etc., without polluting global space.


🏁 Bonus: npm list

🧠 What it does:

Displays installed dependency tree.

npm list --depth=0

Helps diagnose version conflicts or confirm what's installed.


🧪 Final Thoughts

Mastering these npm commands can save you hours of debugging, help automate workflows, and streamline your development process. Whether you’re building APIs, web apps, or libraries, these are foundational tools every developer should be comfortable with.


🔁 Summary Table

CommandDescription
npm initStart a new project
npm installInstall dependencies
npm uninstallRemove a package
npm updateUpdate installed packages
npm auditCheck for vulnerabilities
npm runRun project-specific scripts
npm ciFast, clean install (ideal for CI)
npxRun package without installing globally
npm listView installed package tree
npm outdatedCheck what’s out of date