How can I get the path to the global npm_modules within javascript?
From 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 within a javascript file? Is there some module I can use to get this path?
I am trying to configure my protractor.config.js file to specify the paths for seleniumServerJar and chromeDriver, (which are installed globally), and I need to know the path to the global npm modules so I can specify these paths.
What you can do is call the shell command from your script:
var exec = require('child_process').exec;
exec("npm config get prefix", function(err, stdout, stderr) {
console.log(stdout);
});
There is an environment variable NODE_PATH which is how node finds its node_modules dir
console.log(process.env.NODE_PATH);