Last Updated: May 30, 2018
·
18K
· mikaelbr

NPM to bump module version

You can use the NPM CLI to bumb the version of your Node.js module. If the NPM module is in a git repo, it will also make a commit.

NPM version manual:

npm version [<newversion> | major | minor | patch | build]

You can specify a commit message using the -m (or --message) argument. In the commit message you can insert the new version number by using the %s placeholder.

See example of usage below:

➜  tmp git:(master) cat package.json | grep version    
  "version": "0.0.0",
➜  tmp git:(master) npm version 0.1.0-alpha
v0.1.0-alpha
➜  tmp git:(master) cat package.json | grep version                  
  "version": "0.1.0-alpha",
➜  tmp git:(master) npm version major
v1.0.0
➜  tmp git:(master) npm version major
v2.0.0
➜  tmp git:(master) npm version minor
v2.1.0
➜  tmp git:(master) npm version patch -m "Bumped to version %s"
v2.1.1
➜  tmp git:(master) npm version build
v2.1.1-1
➜  tmp git:(master) npm version build -m "Bumped to version %s"
v2.1.1-2
➜  tmp git:(master) git log --pretty=format:"%h - %s"         
1448ad8 - Bumped to version 2.1.1-2
5a5cc37 - 2.1.1-1
591cd42 - Bumped to version 2.1.1
dcf1fa9 - 2.1.0
325e69a - 2.0.0
f89c461 - 1.0.0
c419a8a - 0.1.0-alpha
7cf4ac4 - initial commit
➜  tmp git:(master) cat package.json | grep version 
  "version": "2.1.1-2",

Edit: For cross package manager handling of the same way (for bower, jquery-plugins, jam, etc) see mversion

1 Response
Add your response

Note that the newest version of npm is using prerelease instead of build

over 1 year ago ·