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.
MAJORVersion for API with big new features and or incompatible with last version.MINORVersion with aditional features and compatible with current major version.PATCHVersion with bug fix and compatible with current major version.
Range
~: Accept any patch update within the same minor. Ex:~1.1.0will accept any version from1.1.0to1.1.xbut not1.2.xor higher.^: Accept any minor or patch update. Ex:^1.1.0will accept any version from1.1.0to1.x.xbut not2.x.xor 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.0will accept version from1.1.0to1.x.xbut not greater than2.0.0.-: Accept specific range of version using dash. Ex:1.1.0 - 1.5.0will accept version from1.1.0to1.5.0inclusive.||: Combine multiple ranges using OR operator. Ex:^1.1.0 || ^2.1.0will accept version from1.1.0to1.x.xOR from2.1.0to2.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. 👋