Short solution, no external module needed (synchronous alternative to Edin’s answer):
revision = require('child_process')
.execSync('git rev-parse HEAD')
.toString().trim()
and if you want to manually specify the root directory of the git project, use the second argument of execSync to pass the cwd option, like execSync('git rev-parse HEAD', {cwd: __dirname})