Update all the Node.js dependencies to their latest version

mrbotdeveloper

Mr. Developer

Posted on June 28, 2022

Update all the Node.js dependencies to their latest version

How Packages Become Dependencies

When you install a package using npm install <packagename>, the latest version is downloaded to the node_modules folder. A corresponding entry is added to package.json and package-lock.json in the current folder.

npm determines the dependencies and installs their latest versions as well.

To discover new package releases, use npm outdated.

Some of those updates are major releases. Running npm update won't help here. Major releases are never updated in this way because they (by definition) introduce breaking changes, and npm wants to save you trouble.

Update All Packages to the Latest Version

Leveraging npm-check-updates, you can upgrade all package.json dependencies to the latest version.

1. Install the npm-check-updates package globally:

npm install -g npm-check-updates
Enter fullscreen mode Exit fullscreen mode

2. Now run npm-check-updates to upgrade all version hints in package.json, allowing installation of the new major versions:

ncu -u
Enter fullscreen mode Exit fullscreen mode

Note ⚠️: A slightly less intrusive (avoids a global install) way of doing this if you have a modern version of npm is:

npm install npm-check-updates

And then run the update command.

npx npm-check-updates -u

3. Finally, run a standard install:

npm install
Enter fullscreen mode Exit fullscreen mode
πŸ’– πŸ’ͺ πŸ™… 🚩
mrbotdeveloper
Mr. Developer

Posted on June 28, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related