- Major Version: When incompatible API changes were made.
- Minor Version: When functionality is added in a backwards compatible manner.
- Patch Version: When backwards compatible bug fixes were made.
All other pre-release labels and build metadata is an extension to MAJOR, MINOR, PATCH format.
Update package npm (latest version)
This command updates all the packages involved to the latest version. It also installs missing packages if any. Specify the name/ flag or else all packages in the specified location(local or global) will get updated.
Local package update:
- Steer to your program’s root directory and confirm that local package contains package.json file: cd/path/to/program.
- npm update: Run this update command.
- Run the older command, there should not be any result. This will test the update.
To update npm package version number (published)
- Run the following command on command line present in the program root directory: Replace <update_type> with (patch, minor or major):npm version <update_type>
- Run publish npm.
^ And ~ Meaning in detail
Again and again a version has a ^ in front of it (e.g. ^16.8.6). This implies that brand new version can be carefully or safely installed. If the newest version in 16.x then you can harmlessly installed ^16.12.1. At time a version has a ~before it. (e.g. ~16.8.6). The version which can be safely installed i.e the latest patch version. Example : If newest version is in 16.8.x then you can can safely installed ^16.8.12.
Is install NPM installs the latest version of the dependencies or Not?
NPM install would not update any packages, if the packages have previously installed into the mode_module folder. If the packages never even installed and a package-lock.json file exists, then npm install will install the correct dependency versions described in package-lock.json.
The latest safe version of the dependencies will be installed by npm install, if they don’t exist in the node_modules folder and, there is no package-lock.json file.Anyhow , you can think that the latest safe version hasn’t been installed because package.json is constant., but if you check the node_modules folder and packages in it, the new safe version will turned out to be installed. How can you successfully update all your dependencies Some such dependencies that are out of date can be managed by managing the following some commands. npm outdated
The dependencies will be put together as in the image:
The latest version is the wanted version that can be taken (as reported by the semantic version and the ^ or ~ prefix).The latest version is the new versi on which is available in the npm registry.
By following this command, all the dependencies can be updated to the Wanted version:
Moreover upgrading the packages in the node_modules folder. The package.json and package-lock.json record will be updated.
If you dont want to update your all packages, then the package names can be describe at the last of the command:
npm update “react” “react-dom”
React is shown in the above example.
Also Read: How much Mobile App Development cost in 2021?
Upgrading all dependencies with some important changes
How do you upgrade dependencies, When there is a major version change? Perhaps, the best way is as follows:
You have to check the Changelog of the Dependent Package, that can affect Your app.
If you feel that you are safe to update, follow these commands.
npm install <packagename>@latest
You can list them all if all the packages run together. The below example will upgrade the react to the latest version:
npm install react@latest react-dom@latest
Do not verify the app by doing some tests. Follow the same process for the other packages, which was for the major version.
Is There a quick way by which you can update all your dependencies, Including major version changes? So, like npm update but also for major version update?
Yes, there is a tool called npm-check-updates that will do this. Just run the following command: We have a tool named npm-check-updates that will do this, so follow these command.
npx npm-check-updates -u
Dependencies will be updated to the latest version (including version changes in json package file). We need to run the following command if we are happy to go ahead with the upgrades “npm install”. All the packages in node modules folder will be upgraded and the package-lock.json file will also be upgraded.
- To discover dependencies that are outdated use npm outdated.
- Perform safe dependencies upgrades by using npm update.
- To upgrade all dependencies to their latest major versions use npm install and npm-check-updates.
- To upgrade the latest major version use nPm install<packagename>@1latest.