---
title: "Comment by Umair Hafeez on \"Managing multiple node versions with NVM\" | Hashnode"
description: "NVM is great indeed, thank you for putting this together Chris Bongers . I use this tiny shell script in my .zshrc file that looks for a .nvmrc file, and automa"
url: "https://hashnode.com/posts/managing-multiple-node-versions-with-nvm/62cea318fe5b55d5da426f13/comment/62d1aa122f551b044bc154fa"
---

[Discussion](https://hashnode.com/posts/managing-multiple-node-versions-with-nvm/62cea318fe5b55d5da426f13)

Comment [Managing multiple node versions with NVM](https://hashnode.com/posts/managing-multiple-node-versions-with-nvm/62cea318fe5b55d5da426f13)

[Umair Hafeez](https://hashnode.com/@umairhafeez)

[Jul 15, 2022](https://hashnode.com/posts/managing-multiple-node-versions-with-nvm/62cea318fe5b55d5da426f13/comment/62d1aa122f551b044bc154fa)

NVM is great indeed, thank you for putting this together [Chris Bongers](https://hashnode.com/@dailydevtips).

I use this tiny shell script in my `.zshrc` file that looks for a `.nvmrc` file, 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-nvmrc
```

It will help those who don't use VS Code 🙂
