Use .nvmrc Automatically When You Enter a Directory

Do you regularly forget to run nvm use when you enter a Node.js project directory? Now you can have nvm use run automatically when you cd into a directory with an .nvmrc file.

Put this in your .bashrc or .zshrc:‌‌

function cd {
    # actually change the directory with all args passed to the function
    builtin cd "$@"
    # if there's a named ".nvmrc"...
    if [ -f ".nvmrc" ] ; then
        # Make nvm use the specified node version
        nvm use
    fi
}
comments powered by Disqus
Find me on Mastodon