What is the difference between the command npm update
and the package npm-check-updates? Is it fully safe to use the latter?
It seems after executing npm update
not all packages are updated, thus it seem it is incomplete. Many other popular SO answers refer to use first the prior command and then the latter, but I still do not understand what the latter does that the prior does not.
A bit late to the party but I felt like the previously accepted answer is outdated and slightly lacking.
npm update
- updates the dependencies both in package.json and package-lock.json in accordance to the semantic version rules defined in package.json
.
Key features of npm update
:
package.json
file with npm update --package-lock false
. However, this flag will completely ignore package-lock.json
and hence automatic pruning of extraneous modules will also be disabled.npm update
will perform with the flag --dry-run
, without actually updating.npm outdated
- shows all the packages that have newer versions available, this includes breaking changes.
It prints a table that includes the package, the current version, the wanted version - according to the semver rules in the package.json
- the latest version and the location of the package.
Running ncu
without any flags will print a list of all the outdated packages and the version to which it would update, but will not apply any changes.
ncu --update
- apply changes to the package.json
file only. It will change the versions of all the dependencies in package.json
to the latest (even if it's a breaking version!), but will not modify the package-lock.json
file. For that, you will need to run npm install
.
ncu --target [patch, minor, latest, newest, greatest]
- choose which type of version to list/update.
Feature | npm | ncu |
---|---|---|
Show Outdated Packages | npm outdated - shows wanted & latest versions |
ncu - shows latest by default, can be customised |
Update Packages | npm update |
ncu -u |
Breaking Versions | Never updates to a breaking version, but shows them in npm outdated |
Updates to and shows breaking version by default, can be customised |
package.json SemVer Rules |
npm outdated shows the "wanted" version according to SemVer rules, updates to "wanted" version |
Disregards SemVer rules (unless explicitly specified), can be customised to update to different types of versions |
Files Modified | Modifies package.json and package-lock.json and installs the updated modules |
Modifies package.json , doesn't change package-lock.json and doesn't automatically install |
Customisation | Can ignore package-lock.json (npm@7) and choose which packages to update |
Can choose what kind of version to update to (minor, patch, latest, greatest, newest) and which packages to update |