How can I get the path to global npm_modules in javascript?

How can I get the path to global npm_modules in javascript?

From the command line, I can get the base path to the npm modules by calling this:

npm config get prefix

How can I get this path in javascript file? Is there any module that I can use to get this path?

I am trying to set up a protractor.config.js file to specify paths for seleniumServerJar and chromeDriver (which are installed globally), and I need to know the path to the npm global modules so that I can specify these paths.

+4
source share
2 answers

There is an NODE_PATH environment variable since node finds its node_modules dir

console.log(process.env.NODE_PATH);
+1
source

, script:

var exec = require('child_process').exec;
exec("npm config get prefix", function(err, stdout, stderr) {
    console.log(stdout);
});
0

All Articles