Skip to content

Instantly share code, notes, and snippets.

@nicolas-amabile
Created May 20, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolas-amabile/95fbb2d4131d73f0e625efbaf5a35da2 to your computer and use it in GitHub Desktop.
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
# 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"'
@nicolas-amabile
Copy link
Author

Another approach is to have a .nvmrc file for each project and simply run nvm use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment