DEV Community

Erin Bush
Erin Bush

Posted on

TIL about automatically bumping NPM versions

Do you need to update a bunch of packages? Do they all have a similar scope* or name?

npm-check-updates checks the packages listed in your package.json file, and prints out a list of the packages that can be updated to the latest version.

To install:

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

Then, run it in your project folder:

ncu 
Enter fullscreen mode Exit fullscreen mode

You’ll get some output that looks a little something like this:
sample output from npm-check-updates

If you want it to automatically bump the versions in your package.json file you can pass in the update parameter:

ncu -u
Enter fullscreen mode Exit fullscreen mode

You can also run it with a regex string if you are just curious about a certain scope or package:

ncu '/^@npm.*$/' -u
Enter fullscreen mode Exit fullscreen mode

Remember to run npm install afterwards to actually install the packages since npm-check-updates will just update your package.json file.

Presto-chango you've just saved yourself some seriously tedious file changes!


*PS: scopes in npm are useful if you need to group packages by your organization. In the following example “npm” is the scope.

@npm/package-name
Enter fullscreen mode Exit fullscreen mode

This post was originally published on my blog

Top comments (3)

Collapse
 
vberlier profile image
Valentin Berlier • Edited

I've been using dependabot for keeping my dependencies up to date and it's the best thing ever. It works with virtually every language, it makes a PR when a dependency is out of date and the only thing you have to do is merge it. You can even tell it to merge the PR automatically if your CI checks have passed.

Collapse
 
bycedric profile image
Cedric van Putten

TIL too! I only knew about npm outdated. Here is the link to the repo:

Collapse
 
lfkwtz profile image
Michael Lefkowitz