Effective Engineer: Update all your bower and npm dependencies with one command

If you are front end or full stack software engineer, you usually manage your app’s dependencies in your package.json (NPM) and bower.json (Bower). Do you have the experience that you need to update all the dependencies to the latest version?

 

I understand some developer don’t like to use the latest version of libraries because of compatibility issue. However, I feel most of the time, the updated version of libraries are more stable and reliable (bugs fixed and people’s open source contribution to make the software better). Our team at SolarCity before didn’t update some dependencies to the latest version for one of our apps. However, I found out that one of the error we saw wouldn’t even happen if we use the latest version of the library. Therefore, after discussion, we decide that we would use the latest version of libraries from then on. One problem is that it’s such a pain to update dozens of libraries in our json file.

Here is the package file for my previous project: OpenElect. Oh dear, how many dependencies are there…it will take years to manually update the version number.

package.json example

In the beginning, I searched the npm site for the package and update the number to the latest stable version. After the 5th one, I thought it would take too much of my time. Hence, I started to look for tool helping me. Soon after I googled, I found a great tool:

npm-check-updates

https://www.npmjs.com/package/npm-check-updates

 

With one simple command:

ncu

You can see your libraries’ latest version .

npm check update

 

You can update all of them by this command:

 ncu -u

For bower package, you can type:

ncu -m bower # will use bower.json and check versions in bower

 

So here you are, you can update all your library version with these simple commands. Now we get time to eat donuts. 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *