DEV Community

Cover image for How to update all npm package.json dependencies to the latest version
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Originally published at learn.coderslang.com

How to update all npm package.json dependencies to the latest version

It's essential to keep all the node modules of your project up to date as the security patches go out.

In this short tutorial I'll teach you how to update all the node_modules to the latest version with a single command.

By default, once you type npm install <package_name>, node package manager installs the latest version of
the desired package. This version is then added automatically to the file package.json.

The issue is that over time new versions of the packages are being released, and you need to somehow update them.

To check which packages are outdated, you can run the command npm outdated, however
Node Package Manager (npm), doesn't update dependencies from package.json by default.

So, if you're looking to update all the npm modules with a single command, you can use the module npm-check-updates.
It's best to install this module globally with the -g flag.

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

After successful installation, you'll be able to use the command ncu from the command line.

ncu -u
Enter fullscreen mode Exit fullscreen mode

Make sure that you navigate to your project directory before using the ncu -u command. Once you execute it,
npm-check-updates will update all the dependencies from package.json to the fresh versions.

The last step is to run the command npm install to download and install updated packages based on the information
in package.json.

Top comments (0)