Integrating direnv with nvm

30 Jan 2019 17:12 direnv nodejs

To integrate direnv with nvm, add the following to ~/.direnvrc:

use_nodejs() {
    NODE_VERSION="$1"

    type nvm >/dev/null 2>&1 || . ~/.nvm/nvm.sh
    nvm use "$NODE_VERSION"
}

Then add (e.g.) the following to your project’s .envrc:

use nodejs 10.15.0