Runnin from the console
> npm root -g
Or programmatically
var npm = require("npm");
npm.load(null, function (err, npm) {
npm.config.set("global", true);
npm.root;
});
I get a different results on Windows. The first one returns C:\Users\myuser\AppData\Roaming\npm\node_modules and the second one C:\Program Files (x86)\nodejs\node_modules. The same happens when I install a module, doing this programmatically tries to install it on program files instead of AppData.
Could this be a bug? Or am I doing something wrong?
On linux it works consistently. I've not tried on Mac.
Update: I tried this on Mac and it works fine.
The difference appears to be the npmrc that's included in the Node.js install for Windows:
# C:\Program Files (x86)\nodejs\node_modules\npm\npmrc
prefix=${APPDATA}\npm
It's path positions it to be handled as a builtin config, rather than a global or user config, so "local" installs of npm won't process it. You can see this when executing the local install directly:
> .\node_modules\.bin\npm root -g
C:\Program Files (x86)\nodejs\node_modules