How to check and update npm packages
In our application, we use different npm packages. We need to update the packages from time to time as new versions of packages will be released. If we do not update the packages, they may become obsolete or we may need to use the new function that is available only in the new updates.
These packages need to be updated often to stay in sync. There are many ways we can check for updates. But we will be using
npm-check
as this is simple and UI is interactive.
First of all, we have to install the npm-check package globally
npm install -g npm-check
Then to check for all the updates we have to go in our projects dir where the package.json file is situated and open the terminal in the same directory and type.
npm-check
It will show all the npm packages used with additional information on major updates, minor updates, patch updates and also let us know if the package is being used or not with the links for the packages.
In npm-check, updates are organized by type of updates : patch / minor / major / non semver. So here again, we can select all the patches and update them together. And then we better run the minor/major updates one by one. npm-check also provides us a link to the website of each dependency or at least to its repository.
To show an interactive UI for choosing which modules to update type
npm-check -u
You can move from one library to another by using an arrow up or arrow down. To select the libraries you want to update, you have to press space in front of the chosen one. And finally, to execute the upgrades, you just have to press enter.
Each time you’ll update dependencies, it’ll automatically install the new version and update your package-lock.json file accordingly.
Please be careful while doing the major updates as it can have breaking impact on our project.
Thank You :)