Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Npm install global modules on different location node js

I am on a unix os, ubuntu, and I am experiencing a problem in installing global modules.

When I tried to look up where the node_modules folder is, I found out that npm installed some of my global modules in

/usr/lib/node_modules

and some of them are installed in

/usr/local/lib/node_modules

I have no problem before on using this global modules, until such time I tried installing a generator, that is when I first thought of looking into the directories because, after installing the generator, it says that I haven't installed the generator.

What is odd is that when I tried some of the modules, they work perfectly fine except for the other modules, saying it wasn't installed.

Is there a way to uninstall/remove/clean my computer from nodejs including its module and install it again so that it will just be using a single directory, so there won't be any confusion.

Why do you think npm installed this things in two diff. directories.

like image 656
Joey Hipolito Avatar asked Oct 24 '25 20:10

Joey Hipolito


1 Answers

It looks to me like you have had 2 different versions of nodejs installed. Probably a packaged version and then a new release?

It works because your node folder is probably set to /usr/local/lib/node_modules Node allways traverses the folder tree when looking for modules so if you do a require('imNotHere') it will look in:

/usr/local/lib/node_modules/imNotHere
/usr/local/node_modules/imNotHere
/usr/node_modules/imNotHere
/node_modules/imNotHere

before failing. In your setup modules in /usr/lib/node_modules will still be caught by this

like image 153
Jesper Blaase Avatar answered Oct 27 '25 11:10

Jesper Blaase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!