DEV Community

rahulrao0209
rahulrao0209

Posted on

A Very Short intro to NPM Versioning.

NPM package versions

NPM packages have a version number which looks like 0.0.0 for example.

  • The first digit specifies the major version.
  • The second digit specifies the minor version.
  • The third digit specifies the patch version.

A major version update may not be backward compatible and can have breaking changes that may break your codebase if its using the previous major version.
A minor version update is backward compatible and generally consists of additional functionalities or features.
A patch version is a bugfix version and is backward compatible.

Updating NPM packages

NPM packages can be updated using the

npm update

command.

To update a specific package, use for example -

npm update packagename

To update a package to a specific version, use for example -

npm update packagename@1.0.2

To update all packages in the codebase use - npm update

^ is used to specify that we should only accept minor and patch version updates.

packagename: ^1.0.0

~ is used to specify that we should only accept patch version updates.

packagename: ~1.0.0

* is used to specify that we should accept all version updates.

packagename: *1.0.0

Note - Using * and accepting all version updates is not recommended and can cause breaking changes.

Also, without specifying any of the ^ ~ or * symbols, the packages will not get updated to newer versions.

Top comments (1)

Collapse
 
theaccordance profile image
Joe Mainwaring

One thing worth mentioning in regards to npm and semVer (major.minor.patch) - while this is the intention of versions, it's not strictly enforced. Additionally, developers aren't always great at identifying breaking changes, so you may encounter unpleasant experiences when the new version implies otherwise.

I personally have taken to a different version format for my projects (year.release.patch) as I find it more intuitive when looking at a package.json manifest 5 years from now.