npm
is quite simple but immensely powerful for what we do as developers. At the heart of it, NPM just downloads stuff from its own registry on the Internet. But the underlying dependency management makes it an easy-to-use, super efficient tool. Here are some commands that I find useful in day-to-day work.
Install / Uninstall
Of course, I am joking. You would have seen this a billion times.
|
|
You could follow the shortcut notation
|
|
You can specify the install command without package names so that it can install / refresh all packages listed in package.json.
Initialize folder
You may copy/paste package.json or clone starter repositories to get started.
Or, start from scratch using init
.
|
|
This command will create a blank folder and a baseline package.json for you to get started from.
Run
You may know all commands by heart, but what about that poor maintenance guy?
It is a good idea to standardize commands and their params through the package.json file.
|
|
Now anyone can simply do the following to run or watch application.
|
|
List
Often you provide version numbers in package.json, and cannot quite know what was installed. Or, you could have provided something like so -
|
|
.. which stands for install anything greater than or equal to the version specified within same minor version. i.e., version can be 0.18.0, 0.18.1, 0.18.9, but not 0.19.0 or 1.0.0).
If you want to find exact version in your folder (or from wherever your npm package is running from) - use list.
|
|
Update
You can do an update of specified or all packages.
|
|
The update follows the conditions specified by you using the semantic versioning.
If the version has changed and you want to do a major or minor update to current version specified in package.json.
Identify outdated packages
Use npm outdated
to know which packages have updates available.
|
|
Output -
|
|