Install global nodejs tools in home directory

When installing packages using npm install --global, you need to have sudo rights.
To avoid this you can move this directory inside your home directory and avoid the use of sudo while installing packages.

1
2
3
4
5
6
7
8
9
10
11
# Make sure the directory exists
mkdir -p ~/.npm

# Update npm config
echo 'prefix=~/.npm' >> ~/.npmrc

# Update global path
echo 'export PATH="$PATH:$HOME/.npm/bin"' >> ~/.bashrc

# Reload bash config
source ~/.bashrc