Working a project on nodejs? Do you know how package versioning in package.json?
Overview
If we working with nodejs and using npm, we will see package.json
file in the project. This file contains information about the project and dependencies of the project. These dependencies have version field, but did you know how to write it? It will automaticaly included in package.json if you for example install a package dependency like npm install cors
. But know that you can add and typing it manualy in package.json it self.
Please note that I will explain only version symbol meaning. So this posting will be short. 😉
Requisite
- Terminal knowledge
- NodeJS installed
Version Explanation
Semantic
The format will be like this major.minor.patch
.
MAJOR
Version for API with big new features and or incompatible with last version.MINOR
Version with aditional features and compatible with current major version.PATCH
Version with bug fix and compatible with current major version.
Range
~
: Accept any patch update within the same minor. Ex:~1.1.0
will accept any version from1.1.0
to1.1.x
but not1.2.x
or higher.^
: Accept any minor or patch update. Ex:^1.1.0
will accept any version from1.1.0
to1.x.x
but not2.x.x
or higher.*
: Accept any version or you can say it as a wildcard version. If you update the version, the depedencies will be the latest.>
,<
,>=
,<=
: Accept specific range of version. Ex:>=1.1.0 <2.0.0
will accept version from1.1.0
to1.x.x
but not greater than2.0.0
.-
: Accept specific range of version using dash. Ex:1.1.0 - 1.5.0
will accept version from1.1.0
to1.5.0
inclusive.||
: Combine multiple ranges using OR operator. Ex:^1.1.0 || ^2.1.0
will accept version from1.1.0
to1.x.x
OR from2.1.0
to2.x.x
.
😓 Well these version is alot. But you can undestand it but the symbol it self. Hopefully this article can help you to re-remember what you forget because looooonng time not touching the nodeJS… 😁
See you next article. 👋