npm package major update

Many times you will want to upgrade the npm packages for your applications. You can easily do minor upgrades using npm update. But what happens when you want to do a major upgrade of a package that has a major version upgrade? Luckily, we have an automated solution for this so that you do not have to go through the tedium of doing an npm install package-i-want-to-upgrade@latest.

From your command line prompt on Mac or Linux, all you need to do is run the following command:

npm install $(npm outdated | cut -d’ ‘ -f 1 | sed ‘1d’ | xargs -I ‘$’ echo ‘$@latest’ | xargs echo)

This script will first read all of your outdated packages. Then it will append @latest to their name and run each of them individually.

Contratulations! You have now updated your project to the latest of all dependent npm packages with one simple to run command.

Leave a Comment

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