DEV Community

Hridayesh Sharma
Hridayesh Sharma

Posted on

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. 😀

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
Info Comment hidden by post author - thread only accessible via permalink
webstuff

Could you write another one of these, but were you add a short description about what it does?
Ex:
Install a package locally or globally
Cmd command
If you install lically it will copy the files #location# snd upu can do this and that
If you install globally it wil copy files #location# and you can do this and that

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