Globally install npm packages without sudo

In short, add the following lines to .bashrc

npm config set prefix ~/.npm
export PATH=$HOME/.npm/bin:$PATH

npm config will essentially modify ~/.npmrc to include prefix=~/.npm, where ~/.npm can be any other directory.

Then npm install -g will install to the user directory.