

- PACKAGE.JSON CARET MEANING INSTALL
- PACKAGE.JSON CARET MEANING UPDATE
- PACKAGE.JSON CARET MEANING PATCH
RangesĪ version range is a set of comparators which specify versionsĪ comparator is composed of an operator and a version. VersionsĪ "version" is described by the v2.0.0 specification found atĪ leading "=" or "v" character is stripped off and ignored. Hope this story will help you to clarify all the confusion regarding package.json, npm i vs npm ci command, and Tilde(~) vs Caret(~) symbol.Multiple versions to the utility will just sort them.
PACKAGE.JSON CARET MEANING INSTALL
So, before using any of these two commands we need to decide on whether we want the latest updates of dependencies to be installed in the project or install only mentioned version in the project - if the first case is our decision then we must run npm i command else for the second case we must run npm ci command. This command requires the existence of the package-lock.json file in the project. This command doesn't care about Tilde(~) or Caret(~) symbol in the package.json file. Npm ci - this command installs the exact version of the dependencies mentioned in the package.json and package-lock.json file.

Npm i or npm install - this command installs the latest or updated dependencies depending on Tilde(~) or Caret(~) symbol in the package.json file and overwrites the package-lock.json file and the node-modules folder. Hope it is clear to you how you can manage the different dependency versions in your project by the smart use of the Tilde(~) and the Caret(^) sign. Please remember that every time you add/overwrite the version number in the package.json file remove the package-lock.json file and the node_modules folder before running the command npm i.
PACKAGE.JSON CARET MEANING PATCH
Or, we will add Tilde(~) sign in front of the version number to allow installing only the latest PATCH update.įor example, ^5.0.0 version number allows to install 5.3.0 version (while writing this blog this is the latest minor update) and ~5.0.0 version number allows to install 5.0.3 (while writing this blog this is the latest patch update) So, we will add Caret(^) sign in front of the version number to allow installing the latest MINOR with its latest PATCH update.

We will miss any bug-fix-related updates or new functionality-related updates made by the developers of the history library. So, the history library is never going to be updated according to the latest release in its npm repository. Now this project will contain the history version exactly 5.0.0 as we are not adding the ~ or ^ symbol in front of the version number in the package.json file. Step 4: Use of Tilde(~) and Caret(^) Symbol So, our target is to install the exact 5.0.0 version of history is completed. Your NODE-PROJECT-EXAMPLE will look like this. Open the folder in VSCode (or any of your favorite IDE). Step 1: Initialize a ProjectĬreate a folder named NODE-PROJECT-EXAMPLE (or give a name as you wish!) and run the command npm init -y into the folder to initiate a node project. We are going to create a simple node.js project. Let's understand how Tilde(~) and Caret(^) symbol differs when using the npm i (or npm install) and the npm ci command to install dependencies into your project by taking an example.
PACKAGE.JSON CARET MEANING UPDATE
In short, Caret(^) symbol tells the npm i command to install the latest MINOR update whereas Tilde(~) symbol tells the npm i command to install the library only till the latest PATCH update. When using npm i to install project dependencies then the significance of these two symbols easily be understandable.

But before the version number, there may have a special symbol Tilde(~) or Caret(^), which controls the library version to install into the project. In the package.json file, there is a property called dependencies - it contains the name and the version number of different libraries (aka dependencies) used in the project. PATCH version updates when bug fixes in a backward-compatible mannerĪnother point to note is that when the MAJOR version updates it resets the MINOR and PATCH version numbers and when the MINOR version updates it resets the PATCH version number. MINOR version updates when new functionality in a backward-compatible manner addedģ. MAJOR version updates when any incompatible API changes happenedĢ. According to the official documentation of semantic versioning ( ) -ġ. The version number of npm packages has a specific format. To know more about the package.json file you can check its official documentation at this link: 2. This metadata includes - name, homepage, keywords, dependencies, etc properties. This file is simply a JSON file containing the project's metadata. All Node-based projects, npm packages - contain a package.json file usually in the root directory.
