Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the global module installation folder in Node.js

Tags:

node.js

npm

I'm trying to access the location on the disk of the global node modules (from within a node module).

I know I can enter npm root -g on the command line, but this is awfully SLOW.

Does any of you know a way to get this information reliably and in a timely fashion (without requiring users to setup any global Env variables)?

like image 805
Simon Boudrias Avatar asked Dec 12 '13 21:12

Simon Boudrias


2 Answers

You probably cannot do this in pure javascript way, but you can just look for the npm location:

$ which npm
/usr/local/bin/npm
$ ls -al /usr/local/bin/npm
... /usr/local/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

so the global node_modules is /usr/local/lib/node_modules

like image 155
Alex Netkachov Avatar answered Oct 19 '22 05:10

Alex Netkachov


On Windows, It can be done by executing the command : where npm

like image 31
Shaggy Avatar answered Oct 19 '22 07:10

Shaggy