npm check and update package if needed
To check if any module in a project is 'old':
npm outdated
'outdated' will check every module defined in package.json
and see if there is a newer version in the NPM registry.
For example, say xml2js 0.2.6
(located in node_modules
in the current project) is outdated because a newer version exists (0.2.7). You would see:
[email protected] node_modules/xml2js current=0.2.6
To update all dependencies, if you are confident this is desirable:
npm update
Or, to update a single dependency such as xml2js
:
npm update xml2js
To update package.json
version numbers, append the --save
flag:
npm update --save
npm outdated
will identify packages that should be updated, and npm update <package name>
can be used to update each package. But prior to [email protected], npm update <package name>
will not update the versions in your package.json which is an issue.
The best workflow is to:
- Identify out of date packages with
npm outdated
- Update the versions in your package.json
- Run
npm update
to install the latest versions of each package
Check out npm-check-updates
to help with this workflow.
- Install npm-check-updates
- Run
npm-check-updates
to list what packages are out of date (basically the same thing as runningnpm outdated
) - Run
npm-check-updates -u
to update all the versions in your package.json (this is the magic sauce) - Run
npm update
as usual to install the new versions of your packages based on the updated package.json