Skip to content

Instantly share code, notes, and snippets.

@djanowski
Created June 28, 2016 15:14
Show Gist options
  • Save djanowski/eb69d253948bc72da054efe9e3f67542 to your computer and use it in GitHub Desktop.
Save djanowski/eb69d253948bc72da054efe9e3f67542 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# `nvm use` the version specified in package.json.
source $(brew --prefix nvm)/nvm.sh
set -eo pipefail
die() {
echo "$@" >&2
exit 1
}
if [[ ! -f package.json ]]; then
die "No package.json found."
fi
NODE_VERSION=$(jq -r .engines.node package.json)
if ! nvm use "$NODE_VERSION"; then
nvm install "$NODE_VERSION"
nvm use "$NODE_VERSION"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment