DEV Community

Hridayesh Sharma
Hridayesh Sharma

Posted on

35 4

11 NPM Commands Every Node Developer Should Know.

1. Create a package.json file

npm init -y # -y to initialize with default values. 
Enter fullscreen mode Exit fullscreen mode

2. Install a package locally or globally

npm i package # to install locally. i is short for install
npm i -g package # to install globally
Enter fullscreen mode Exit fullscreen mode

3. Install a specific version of a package

npm install package@version
Enter fullscreen mode Exit fullscreen mode

4. Install a package as dev dependency

npm i -d package # -d stands for --save-dev i.e install as dev dependency
Enter fullscreen mode Exit fullscreen mode

5.To see all the dependencies of your project

npm list # this will list all the dependencies of the third-party modules as well
Enter fullscreen mode Exit fullscreen mode

6. To see direct dependencies of your project

npm list --depth=0
Enter fullscreen mode Exit fullscreen mode

7. To see the information about a package in your project

npm view package
Enter fullscreen mode Exit fullscreen mode

8. See specific information from package.json of a third-party package like dependencies of the package

npm view package dependencies
Enter fullscreen mode Exit fullscreen mode

9. To check different versions available for a package

npm view package versions
Enter fullscreen mode Exit fullscreen mode

10. Check outdated packages in your project

npm outdated # run with -g flag to check globally
Enter fullscreen mode Exit fullscreen mode

11. To update the packages

npm update
Enter fullscreen mode Exit fullscreen mode

I hope this helps. Let me know if you use any other commands that can be helpful.

Thanks for reading. 😀

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (7)

Collapse
 
mirzaleka profile image
Mirza Leka

I would add a 12th - npm audit.
Nice article btw.

Collapse
 
vyasriday profile image
Hridayesh Sharma

Thanks for the appreciation Mirza Leka. :)

Collapse
 
detzam profile image
webstuff
Comment hidden by post author
Collapse
 
vyasriday profile image
Hridayesh Sharma

Hi webstuff. There is a short description for the commands already. Specifying exactly where the package gets installed isn't really necessary. When you will run the commands you will know better what they do. I wanted to keep it as a reference only.

Collapse
 
flipfloop profile image
Victor Guyard

What about
npm prune and npm dedupe?

Collapse
 
budski82 profile image
William Rutkowski

npm -l

Collapse
 
vyasriday profile image
Hridayesh Sharma

That's no longer required when you run it in a Node project. Running npm i adds it to your package.json as well.

Some comments have been hidden by the post's author - find out more

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

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay