简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM