.bash_profile for Git and NodeJS users
Published in
2 min readMar 15, 2019
I am a Mac user, a git user, a nvm user, a NodeJS/npm user.
Here I share useful .bash_profile settings that worked for me all the time.
To run a command at `.node_modules/.bin directory`,
export PATH=$HOME/bin:./node_modules/.bin:$PATH
Without this setting, you need to specify ./node_modules/.bin/XXX
to run node_modules commands such as http-server
.
With this PATH setting, you can run command better.
To make use of .nvmrc
The following lines of code change your nvm environment automatically without your unnecessary $ nvm use X.XX
command.
use_nvmrc() {
if [ "$PWD" != "$PREV_PWD" ]; then
PREV_PWD="$PWD";
if [ -e ".nvmrc" ]; then
nvm use;
else
nvm use default;
fi
fi
}if [ `command -v use_nvmrc` ]; then
export PROMPT_COMMAND="$PROMPT_COMMAND use_nvmrc;"
fi
Without the above setting, you have to switch nvm version manually although you have .nvmrc with the version you require.