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)?
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
On Windows, It can be done by executing the command : where npm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With