Simon Boudrias
Simon Boudrias

Reputation: 44649

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)?

Upvotes: 6

Views: 35615

Answers (2)

Shaggy
Shaggy

Reputation: 764

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

Upvotes: 3

Alex Netkachov
Alex Netkachov

Reputation: 13562

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

Upvotes: 14

Related Questions