Skip to content

Instantly share code, notes, and snippets.

@itsjavi
Last active March 28, 2023 12:44
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 itsjavi/53eb4da9d7ad3d05f9ff0417726b2081 to your computer and use it in GitHub Desktop.
Save itsjavi/53eb4da9d7ad3d05f9ff0417726b2081 to your computer and use it in GitHub Desktop.
Switch node version in the current zsh session, depending on an env var
export N_SESSION_NODE_VERSION=18
# Then, in your PHPStorm or Webstorm project settings you can configure the
# Terminal to override this value via N_SESSION_NODE_VERSION_OVERRIDE, e.g.:
# N_SESSION_NODE_VERSION_OVERRIDE=16
#
export N_NODE_VERSION=${N_SESSION_NODE_VERSION_OVERRIDE:-$N_SESSION_NODE_VERSION}
if [[ $(node --version) == "v$N_NODE_VERSION"* ]]; then
echo "Current node version is: $(node --version). N_SESSION_NODE_VERSION=${N_NODE_VERSION}"
else
echo "Switching node version to '${N_NODE_VERSION}'"
n "${N_NODE_VERSION}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment