Created
May 20, 2020 18:42
-
-
Save nicolas-amabile/95fbb2d4131d73f0e625efbaf5a35da2 to your computer and use it in GitHub Desktop.
Tired of manually switching node versions when changing projects? Alias for the rescue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add those aliases to your favorite alias file | |
# nvm is required | |
alias get-required-node="node -pe \"try { require('./package.json').engines.node.replace(/[>=]/g, ''); } catch (e) { }\"" | |
alias use-required-node='[[ `get-required-node` != undefined ]] && nvm use `get-required-node` || echo "No package.json here"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another approach is to have a
.nvmrc
file for each project and simply runnvm use