Open In App

NPM Version

Last Updated : 13 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

NPM, which stands for Node Package Manager, is the default package manager of Node.js. Developed by Isaac Z. Schlueter, NPM is written in JavaScript and was initially released on the 12th of January, 2010. As the default package manager, NPM is used to manage all the packages and the modules in Node.js. We can do so using the command line client npm.

In this article, we are going to talk about the command npm version.

NPM version

The npm version command provided by npm is used by the developers to manage their package versions in an easy to go way. The command updates the version number in the package.json file

Syntax:

npm version version_name

Parameters:

  • version_name: The string or number defining the version.

Now that we have some basic understanding of the npm version command, we will take a look at some examples to understand how we can use the command. The following is the current content in the package.json file:

Screenshot-2024-05-05-at-122916-PM
Initial content of package.json

Examples:

Example 1: Patch Version

We can use the command with the argument patch to update the patch version of the package. The following command increments the patch version.

npm version patch

Output: The following is the content of the package.json file after running the command:

Screenshot-2024-05-05-at-122958-PM
Content of package.json after patch version update

Example 2: Minor Version

We can use the command with the argument minor to update the minor version of the package. The following command increments the minor version:

npm version minor

Output: The following is the content of the package.json file after running the command:

Screenshot-2024-05-05-at-123051-PM
Content of package.json after minor version update

Example 3: Major Version

We can use the command with the argument major to update the major version of the package. The following command major the patch version:

npm version major

Output: The following is the content of the package.json file after running the command:

Screenshot-2024-05-05-at-123130-PM
Content of package.json after major version update

Example 4: Custom Version

Apart from the different strings, we can provide a custom version number to the command. The following command updates the version to be 19.19.19:

npm version 19.19.19

Output: The following is the content of the package.json file after running the command:

Screenshot-2024-05-05-at-123201-PM
Content of package.json after custom version update

Conclusion

In this article, we had a chance to look at the npm version command. We understood what the command does and learnt about its syntax. Finally we had the chance to look at a few examples demonstrating the usage of the command.


Next Article

Similar Reads