In the package.json file, versions
of installed packages can be specified
in various formats. Let's explore these
formats using the imaginary somelib library.
The following example requires the
exact 2.4.2 version:
{
"dependencies": {
"somelib": "2.4.2"
}
}
The following example requires the
latest version compatible with
2.4.2:
{
"dependencies": {
"somelib": "^2.4.2"
}
}
In the following example, the project
works with the versions 2.4.2,
2.4.3, 2.4.4 and so on:
{
"dependencies": {
"somelib": "~2.4.2"
}
}
In the following example, the project
works with the versions 2.4,
2.5, 2.6 and so on:
{
"dependencies": {
"somelib": "~2.4"
}
}
In the following example, the project
works with any patch version of the
2.4 package:
{
"dependencies": {
"somelib": "2.4.x"
}
}
In the following example, the project
works with any minor version of
2 version:
{
"dependencies": {
"somelib": "2.x"
}
}
In the following example, the project
works with the 2.4 version
and higher:
{
"dependencies": {
"somelib": ">=2.4"
}
}
In the following example, the project
works with any version in the range
from 2.4.2 to 3.1.1:
{
"dependencies": {
"somelib": "2.4.2 3.1.1"
}
}