Skip to content

Instantly share code, notes, and snippets.

@peterlazar1993
Created January 22, 2023 17:21
Show Gist options
  • Save peterlazar1993/1ee7dbd65add9dbddded5c76a7b00a35 to your computer and use it in GitHub Desktop.
Save peterlazar1993/1ee7dbd65add9dbddded5c76a7b00a35 to your computer and use it in GitHub Desktop.
script as alias for node to use node via nvm
#!/usr/bin/env sh
# Use the version of node specified in .nvmrc to run the supplied command
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm_rc_version > /dev/null 2> /dev/null
HAS_NVM_RC=$?
if [[ "$HAS_NVM_RC" == "0" ]] ; then
nvm run $*
else
nvm run default $*
fi
exit $?
@peterlazar1993
Copy link
Author

peterlazar1993 commented Jan 22, 2023

The above script is useful to run node in environments where user shell is not loaded, for eg. xcode run scripts phase
Place this as /usr/local/bin/node

Make sure to set right permissions to make it executable - sudo chmod +x /usr/local/bin/node

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