Better npm & node_modules

Better npm & node_modules

Here's a way to - Install node packages globally without using sudo - avoid node-modules sprawl.... by having a single common set of node_modules - reduce bandwidth by avoiding download the same thing over and over again

Here's how I did it;

1) Create a new directory on our home folder for npm/node_modules

mv ~/.npm ~/npm_global

2) Tell npm to use this directory instead

echo "prefix = ~/npm_global" > ~/.npmrc

3) make sure node packages here are executable

export PATH=~/npm_global/bin:$PATH

4) Test it by installing Express

ls ~/npm_global/lib/node_modules
>           #empty directory...

npm install express -g

ls ~/npm_global/lib/node_modules
>express

5) Test Express

express -V
> 3.4.8

6) Check it works

Create a directory for a 'rtest' node project mkdir ~/npm_freedom_test cd ~/npm_freedom_test

Link... don't install
npm link express

Check it worked
ls node_modules

>express

Credit: http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears