How to Update All the NPM Dependencies in a NodeJS Project
Do you need to update all of the NPM package dependencies in the
package.jsonfile for your Node.js application?
When you install an NPM package dependency for your Node.js project, the latest version of that package will be installed (unless you specify otherwise). And the package and it's sub-dependencies are placed in a
node_modulesdirectory in the root of your project folder and are also listed in your
Using NPM, you can run the
npm updatecommand when inside your Node.js project. This will update all the packages listed to the latest version.
$ npm update
But if any of the updates are major releases,
npm updatewon't update those because they may contain breaking changes to your application.
To help with these kinds of updates, we can use the npm-check-updates npm package. This package will only update the dependencies listed in your
package.jsonfile, so we'll have to run the
npm installcommand after we use the
Install the package globally on your machine with this command:
$ npm install -g npm-check-updates
When that's done installing, we can use the npm-check-updates
ncucommand anywhere on our machine.
To update the versions of the
devDependencieslisted in your
package.jsonfile, execute this command in the root of your project directory:
You should see an output similar to this on your command line:
[====================] 11/11 100%
disqus-react ^1.0.5 → ^1.0.7
express ^4.14.0 → ^4.17.1
next ^8.1.0 → ^9.0.7
react ^16.8.6 → ^16.10.1
react-dom ^16.8.6 → ^16.10.1
Run npm install to install new versions.
Notice that the different types of updates are colored differently: green, blue, or red.
package.jsonfile and notice that any outdated package versions now have the newest version listed.
Execute this command to install those updates and replace the old versions:
$ npm install
When the new packages are done installing, test out your application to make sure everything still works correctly. Some of the package updates may have breaking changes in them.
Hopefully, this was helpful in your Node.js project.
Thanks for reading and happy coding!