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

Discussion (8)

Collapse
mirzaleka profile image
Mirza Leka

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

Collapse
vyasriday profile image
Hridayesh Sharma Author

Thanks for the appreciation Mirza Leka. :)

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 Author

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