It feels too slow to load .nvm for each prompt. Instead I indicate the default version of Node I want to use. Works well everywhere unless I need to use older code.
This function scans for a .nvmrc
in the dir you've switched to, if it's present it will:
- identify the node version
- load the nvm environment
- switch to the node version.
The bottom of my .zshrc looks like:
# dont load nvm (too slow), just put the version you want on your path.
export PATH=$PATH:/Users/faizn1/.nvm/versions/node/v8.4.0/bin
function chpwd {
if [[ -a .nvmrc ]]; then
CURRENT_NVER=`node -v`
NVER=`cat .nvmrc`
if [ "$CURRENT_NVER" != "$NVER" ]; then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
eval "nvm use $NVER"
fi
fi
}