node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



This module will return the current project version string. The version string is made of the last git tag or package.json version (if no git tag exists) and the last commit hash.

Table Of Contents


$ npm install get-project-version


Example - Basic Usage

The following is a basic example:

import getProjectVersion from 'get-project-version';
const version = getProjectVersion();
console.log(version); // Version: 1.0.0 Commit: 081b152 

Example - Using Template

This example shows how you can customize the output of get-project-version using a template string:

import getProjectVersion from 'get-project-version';
const version = getProjectVersion({
  template: '{{version}}-{{commit}}'
console.log(version); // 1.0.0-081b152 

Example - Using CWD

There are cases where you'd like to output a version string for a particular folder this can be done like this:

import getProjectVersion from 'get-project-version';
const version = getProjectVersion({
  cwd: 'pathToProjectDir/'
console.log(version); // 1.0.0-081b152 


const version = getProjectVersion([options]);

Options you can pass getProjectVersion:

  • template - An optional String which templates the output of getProjectVersion. Version will be injected into {{version}} and a shortened commit hash will be injected into {{commit}}. eg. '{{version}}-{{commit}}'
  • cwd - An optional String. By default the current working directory will be process.cwd() you can modify this by passing a path. eg. 'pathToProjectDir/'


CLI Example - Basic

$ get-project-version

The above would output to stdout something like Version: 1.0.0 Commit: 081b152

CLI Example - Template

$ get-project-version --template '{{version}}-{{commit}}'

The above would output to stdout something like 1.0.0-081b152

CLI Example - CWD

$ get-project-version --cwd pathToProjectDir/

The above would output a version string for pathToProjectDir/


MIT, see for details.