DEV Community

Cover image for 10 Essential NPM Commands for Beginners
Mahmudur Rahman
Mahmudur Rahman

Posted on • Edited on

10 Essential NPM Commands for Beginners

Are you just starting with Node.js and NPM (Node Package Manager)? NPM is a powerful tool that helps developers manage packages and dependencies in their projects. Here’s a quick guide to the 10 essential NPM commands you should know as a beginner:


1. npm init

Creates a new package.json file for your project, where all your dependencies and scripts are tracked.

npm init
Enter fullscreen mode Exit fullscreen mode

For a quicker setup, use:

npm init -y
Enter fullscreen mode Exit fullscreen mode

2. npm install (or npm i)

Installs the dependencies listed in your package.json. You can also use it to install new packages:

npm install <package-name>
Enter fullscreen mode Exit fullscreen mode

For a specific version:

npm install <package-name>@<version>
Enter fullscreen mode Exit fullscreen mode

3. npm install -g

Installs a package globally, making it available across your system. Useful for tools like create-react-app or nodemon:

npm install -g <package-name>
Enter fullscreen mode Exit fullscreen mode

4. npm uninstall

Removes a package from your project:

npm uninstall <package-name>
Enter fullscreen mode Exit fullscreen mode

5. npm update

Updates all outdated packages in your project:

npm update
Enter fullscreen mode Exit fullscreen mode

To check outdated packages first:

npm outdated
Enter fullscreen mode Exit fullscreen mode

6. npm start

Runs the start script defined in your package.json:

npm start
Enter fullscreen mode Exit fullscreen mode

Default scripts can be customized in the scripts section of your package.json.


7. npm run

Runs custom scripts from your package.json. For example, if you have a script named build:

npm run build
Enter fullscreen mode Exit fullscreen mode

8. npm list

Lists installed dependencies in your project:

npm list
Enter fullscreen mode Exit fullscreen mode

For global packages:

npm list -g
Enter fullscreen mode Exit fullscreen mode

9. npm cache clean

Clears the NPM cache to fix potential issues:

npm cache clean --force
Enter fullscreen mode Exit fullscreen mode

10. npx

Runs CLI tools or executes Node.js packages without installing them globally:

npx create-react-app my-app
Enter fullscreen mode Exit fullscreen mode

Think of it as a one-time-use tool installer and runner.


Final Tips

  • Always monitor your dependencies in package.json to maintain project organization.
  • Utilize version control (like Git) to track changes in your project dependencies.
  • If you're juggling multiple projects, tools like nvm (Node Version Manager) can assist you in managing different Node.js versions.

NPM is a user-friendly tool; the more you use it, the easier it becomes! Let me know which command you found most helpful, or share your own tips in the comments! 🚀


Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs