Update all the Node dependencies to their latest version
How do you update all the npm dependencies in the package.json file, to their latest available versions? Warning: Updating the package versions to the latest ones might break your code.
When you run npm install inside your application directory it simply installs the packages according to the version that is defined in the package.json.
If you are adding a new dependency to your project and if you want to add it to your package.json, just run npm install inside your application root directory.
In some cases, probably in old projects, you might wanna update the version of all your dependencies at once. For minor releases, I suggest you can just go ahead and update the dependencies. For major releases, updating the version of your dependencies might break your code. Make sure you test your code after updating is done.
To check if there are new versions for your dependencies:
You will get an output like this.
Package Current Wanted Latest Location agenda 2.1.0 2.2.0 2.2.0 server mongodb 3.3.3 3.3.3 3.3.5 server mongoose 5.7.4 5.7.13 5.7.13 server oracledb 4.0.1 4.1.0 4.1.0 server winston-daily-rotate-file 4.2.1 4.3.0 4.3.0 server
To update to a new major version all the packages:
npm install -g npm-check-updates
To upgrade all the version hints in the package.json file, to dependencies and devDependencies.
Run npm update
Install all the packages to package.json
If you see any warnings related to vulnerabilities, just run npm audit fix to fix those warnings. Some vulnerabilities require manual review.
Leave a Reply