The npm tool supplies other functionality to help with module creation and management workflow.
For instance, the npm version command can allow us to manage our module's version number according to SemVer semantics.
SemVer is a versioning standard. A version consists of three numbers separated by a dot, for example, 2.4.16. The position of a number denotes specific information about the version in comparison to the other versions. The three positions are known as MAJOR.MINOR.PATCH. The PATCH number is increased when changes have been made that don't break the existing functionality or add any new functionality. For instance, a bug fix will be considered a patch. The MINOR number should be increased when new backward compatible functionality is added. For instance, the adding of a method. The MAJOR number increases when backwards-incompatible changes are made. Refer to http://semver.org/ for more information.
If we were to a fix a bug, we would want to increase the PATCH number. We can either manually edit the version field in package.json, setting it to 1.0.1, or we can execute the following:
npm version patch
This will increase the version field in one command. Additionally, if our module is a Git repository, it will add a commit based on the version (in our case, v1.0.1), which we can then immediately push.
When we ran the command, npm output the new version number. However, we can double-check the version number of our module without opening package.json:
npm version
This will output something similar to the following:
{ 'hsl-to-hex': '1.0.1',
npm: '2.14.17',
ares: '1.10.1-DEV',
http_parser: '2.6.2',
icu: '56.1',
modules: '47',
node: '5.7.0',
openssl: '1.0.2f',
uv: '1.8.0',
v8: '4.6.85.31',
zlib: '1.2.8' }
The first field is our module along with its version number.
If we added a new backwards-compatible functionality, we can run this:
npm version minor
Now our version is 1.1.0.
Finally, we can run the following for a major version bump:
npm version major
This sets our module's version to 2.0.0.
Since we're just experimenting and didn't make any changes, we should set our version back to 1.0.0.
We can do this via the npm command as well:
npm version 1.0.0