DEV Community

Cover image for Update your npm dependencies and your package.json at once !
Stephdotnet
Stephdotnet

Posted on

Update your npm dependencies and your package.json at once !

I recently stumbled upon an new feature of Composer added on 06/22 named composer bump (see this post) which brings a good way to keep track of the updates made to your repository.

As we all know, versionning is essential for the following reasons :

  • Ability to rollback to a previous version of your code
  • Collaborate and handle merge conflicts
  • You can travel back in time to know when a piece of code was modified

That’s why "updating" your composer.json at the same time as running composer update can be a way to know what happened when something goes wrong later.

Composer bump is a great feature

In the end we have something clear and tracked in time

What about NPM ?

While doing my chores on a React project i looked for a similar feature with NPM (Node package manager), but surprisingly there is no such thing !

Chat gpt answer

Chat-GPT struggled with my question... A LOT 😅 Npm version is not the right answer.

The savior: NCU

Sometimes, you’re just glad to find a package that makes everything that you need, and even more. The chosen one is Npm check update made by Raine Revere and it allows you to :

  • List all new dependencies
  • Interactively upgrade them
  • Upgrade your package.json

So if you want to have a package.json file up to date with your locked dependencies just install the package globally

npm install -g npm-check-updates

And run ncu -u to upgrade your package.json
Don’t forget to run npm install to install the updates and to renegerate your package-lock.json

You'll end up with this nice diff while commiting your dependencies update

Package.json upgrade with NCU -u

Hopefully it was useful to you 👋

Top comments (0)