Semantic Versioning in npm

Rumman Ansari   Software Engineer   0000-00-00 00:00:00   35 Share
Subject Syllabus DetailsSubject Details 7 MCQ
☰ Table of Contents

Table of Content:


Semantic Versioning in npm

npm follows Semantic Versioning (semver) for its packages.

Semantic Versioning is a specification where a version is represented by three numbers that represent major/minor/patch version numbers.

Understanding Version Numbers

Consider a package "lodash 4.17.2". Here, 4 represents major version number, 17 represents minor version number and 2 represents patch version number

  • Major Version number: Gets incremented when new features that are not backward compatible are introduced. E.g.: Angular 1, Angular 2

  • Minor Version number: Gets incremented when a new feature is added and does not break any of the existing functionalities.

  • Patch Version number: Gets incremented whenever a bug fix or other minor updates are done.

Installing the Right Version

Sometimes you may want a specific version of a package and not the latest one. In such cases, you can use the following approach.

Install package with a specific major, minor version, and the latest patch version.

>npm install react@15.5 --save

Install a specific major version and the latest minor and patch version.

>npm install react@15 --save

Install the latest version.

>npm install react --save



Checking for Outdated Packages

You should update the packages often so that new features that come with every release of the package are available for use in the project.

For this, first you will need to check if there are any dependency packages that are not the latest.

>npm outdated

This will list all outdated packages, along with the current and latest version of the packages available.

Run this command in the folder "maxbot" which has the package.json and observe.

 

 

Updating Packages

Running "npm update" from the project directory will update all packages in the project to the latest version.

However, it is possible that you may not want the latest version for all dependency packages. In such cases, you can update a specific package.

//Update all dependencies and dev dependencies
>npm update 
//Update a specific package to latest version
>npm update lodash --save
//Update just the dev dependencies
>npm update --dev --save-dev
//Update all packages globally
>npm update -g
//Update npm to latest requires administrative privileges
>npm install npm@latest -g