Always use the right node version

Do you switch between versions of nodejs for different projects, and sometimes (a lot of the times) you forget to actually switch the version? Well, I've got a solution for you!... If you use zsh and nvm, anyway.

Drop this snippet in your .zshrc and you're good to go! All it does right now is check for a .nvmrc file in the same directory, and if that exists, then it'll run nvm use, which will attempt to switch to the version specified by the .nvmrc file. If you don't have the right version installed, it'll whine and you'll need to install it manually, but I hope to automate that soon enough, and I figure that's better than nothing.

Now you just need to add .nvmrc files to all your repos. Fun, right?

function set_node_version() {
    if [ -f "$PWD/.nvmrc" ]; then
        nvm use
    fi
}

add-zsh-hook chpwd set_node_version

Comments (0)

There are no comments to display.

Leave A Comment