Last Updated: February 25, 2016
·
699
· stevelacy

zsh: get npm version of package

I needed to show the current package version when I was in a npm package folder.

get_npm_package_version() {
  local JSON=''
  if [[ -f 'package.json' ]]; then
    echo $(node -e "var pkg = require('./package.json').version; if (pkg) console.log('(npm:'+pkg+')')")
  fi
}

Usage: $(get_npm_package_version)