Making friends: NVM and nodejs deployment

Basically, there are two more or less normal ways of how to deploy nodejs application: shipit and flightplan. They both are not as good as such tools like capistrano for ruby or deployer for php. But, if you desire to use the same ecosystem for deployment as you use for development then you don't have much choices.

Comparing shipit and flightplan, I can say that the first one is more modular and has some good plugins and also supports "rolling releases" feature out of the box, while the last one is simpler.

Both on remote and in local environment I got used to use nvm to switch nodejs versions. And here I faced a problem.

Neither shipit, nor flightplan could see nodejs version that was installed via nvm. Obviously the problem is caused by non-login non-interactive shell that all commands were executed under. That didn't trigger the scripts from .bashrc. Damn, I have never had anything like that with capistrano. It just worked! Googling and seeking through github didn't give much answers. But actually I've found a workaround somewhere. And it works both with shipit and flightplan.

All you need is love a small change in.bashrc file. Just take the following lines:

export NVM_DIR="/home/YOURUSERNAME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

and put them before the following lines:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

This will always load nvm, even if we are in non-interactive mode, which is basically what we need. And it won't hurt anybody.