Managing multiple node versions with NVM
While working on multiple projects, some of them may use different node versions.
This can be a real pain point when you accidentally ran npm install or npm update with a different npm version.
To address these issues, we get something unique called ...
h.daily-dev-tips.com2 min read
NVM is great indeed, thank you for putting this together Chris Bongers.
I use this tiny shell script in my
.zshrcfile that looks for a.nvmrcfile, and automatically switches to the node version defined there, or falls back to the default one if can't find the file.autoload -U add-zsh-hook load-nvmrc() { local node_version="$(nvm version)" local nvmrc_path="$(nvm_find_nvmrc)" if [ -n "$nvmrc_path" ]; then local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") if [ "$nvmrc_node_version" = "N/A" ]; then nvm install elif [ "$nvmrc_node_version" != "$node_version" ]; then nvm use fi elif [ "$node_version" != "$(nvm version default)" ]; then echo "Reverting to nvm default version" nvm use default fi } add-zsh-hook chpwd load-nvmrc load-nvmrcIt will help those who don't use VS Code π