Skip to content

Instantly share code, notes, and snippets.

@patbonecrusher
Forked from gudleik/.envrc
Created June 19, 2018 02:10
Show Gist options
  • Save patbonecrusher/fe763c3efdd00a950976235cb10d0db1 to your computer and use it in GitHub Desktop.
Save patbonecrusher/fe763c3efdd00a950976235cb10d0db1 to your computer and use it in GitHub Desktop.
Node.js direnv setup
# Either use node version specified in package.json
use node package.json
# Or a specific version
use node 5.0.0
# Rest of direnv setup..
export FOO=BAR
use_node() {
layout node
local node_version=$1
if [ "$node_version" == "package.json" ]; then
# Requires jq: `brew install jq`
node_version=`jq --raw-output .engines.node package.json | tr -d "<=> "`
fi
local node_path=${NODE_DIR:-/usr/local/n/versions/node}
if [ -x "$node_path/$node_version/bin/node" ]; then
PATH_add $node_path/$node_version/bin
elif [ -x "$node_path/v$node_version/bin/node" ]; then
# Support nvm users (nvm prefixes versions with 'v')
PATH_add $node_path/v$node_version/bin
else
echo "!!! Node.js version $node_version is not installed"
fi
export NODE_PATH=./node_modules
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment