This page looks best with JavaScript enabled

Short Cheatsheet About NodeJS package.json Versioning

 ·  ☕ 2 min read

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 from 1.1.0 to 1.1.x but not 1.2.x or higher.
  • ^ : Accept any minor or patch update. Ex: ^1.1.0 will accept any version from 1.1.0 to 1.x.x but not 2.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 from 1.1.0 to 1.x.x but not greater than 2.0.0.
  • - : Accept specific range of version using dash. Ex: 1.1.0 - 1.5.0 will accept version from 1.1.0 to 1.5.0 inclusive.
  • || : Combine multiple ranges using OR operator. Ex: ^1.1.0 || ^2.1.0 will accept version from 1.1.0 to 1.x.x OR from 2.1.0 to 2.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. 👋

Share on

AlextraPixel
WRITTEN BY
AlextraPixel
DIY Anywhere - Share any knowledge & Experience for everyone