1. Create a package.json file
npm init -y # -y to initialize with default values.
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
3. Install a specific version of a package
npm install package@version
4. Install a package as dev dependency
npm i -d package # -d stands for --save-dev i.e install as dev dependency
5.To see all the dependencies of your project
npm list # this will list all the dependencies of the third-party modules as well
6. To see direct dependencies of your project
npm list --depth=0
7. To see the information about a package in your project
npm view package
8. See specific information from package.json of a third-party package like dependencies of the package
npm view package dependencies
9. To check different versions available for a package
npm view package versions
10. Check outdated packages in your project
npm outdated # run with -g flag to check globally
11. To update the packages
npm update
I hope this helps. Let me know if you use any other commands that can be helpful.
Thanks for reading. 😀
Top comments (7)
I would add a 12th - npm audit.
Nice article btw.
Thanks for the appreciation Mirza Leka. :)
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
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.
What about
npm prune
andnpm dedupe
?npm -l
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