Here I will note down few npm commands and their usage.
Before starting with the commands, I want to note the semvar notations for npm dependency versions. Node dependencies follow Semvar annotations. Which means: major.minor.patch.
Carret (^) sign means major version has to match and rest can be changed durning update. It is equivalent to 5.x.y, meaning major version has to be 5 but minor or patch version can vary.
Tilda (~) sign means both major and minor version has to match but patch version can change. This is equivalent to 5.4.x, meaning major version has to be 5 and minor version has to be 4 but patch can be updated to latest.
Equal (=) sign refers to exact value. It is equivalent to just writing the version really.
npm update
Updates dependencies that are not fixed. That is does not start with ^
or ~
signs.
npm outdated
Shows the versions that will be updated but does not actually do the update. For example for the following package.json
file:
{"name": "test-package","version": "1.0.0","dependencies": {"lodash": "~4.15.2","express": "^4.17.2"
}}
npm outdated
command yields the following output
Package Current Wanted Latest Location
express MISSING 4.17.2 4.17.2 test-package
lodash MISSING 4.16.6 4.17.21 test-package
npm show <dependency name> versions
This command shows all the versions available for the dependency.
npm show <dependency name> version
This command shows current version for the dependency.
npm install <dependency name>@latest or version number
This will install the latest version or the specific version mentioned. For example npm install lodash@latest
or npm install lodash@4.17