I have two projects with different version of node, which are managed with nvm:
On each project's root folder there is a file .nvmrc with its node version. When I open the integrated terminal on VS Code the default node version is selected (other than the previous two) and I need to type $ nvm use to change to the correct version of node each project uses. Is there a way to execute automatically $ nvm use after terminal opens, or another way to achieve my objective? Sometimes I open the terminal and forget to execute the command.
I'm using Ubuntu 16.04, VS Code 1.20.1 and nvm 0.33.8.
Thanks.
I've found a solution:
To work with nvm, I added in ~/.bashrc (from nvm instructions):
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Now I've changed it to:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
if [ -f ".nvmrc" ]; then
nvm use > /dev/null
else
nvm use default > /dev/null
fi
The --no-use option is to tell nvm "not load default node bin dir on PATH", because it will be done later on the last lines: if .nvmrc exists on the directory where the integrated terminal opens, the version inside .nvmrc will be loaded, default version otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With