2

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.

Miguel Madero
  • 1,948
  • 13
  • 21
  • I've had this happen in an older version of NPM. What version are you using? – Brad Feb 13 '13 at 04:00
  • 1.2.10 (note: SO wants comments to be at least 15 characters so I had to add this note) – Miguel Madero Feb 13 '13 at 04:31
  • This happens too with node 0.10.20 and an `npm install -g npm` after that. At least if the node wasn't a clean install. Maybe in that case it doesn't happen? The npmrc mentioned in the answer didn't even exist. – smhg Oct 28 '13 at 18:59

1 Answers1

4

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
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
  • Should this be changed? Or should the locally installed npm include a similar npmrc? – Miguel Madero Feb 13 '13 at 18:16
  • @MiguelMadero Whether or not it should be changed would likely be up to [`isaacs`](https://github.com/isaacs), [el al.](https://github.com/isaacs/npm/contributors) It may be worthwhile [submitting an issue](https://github.com/isaacs/npm/issues) for it; see how they respond. – Jonathan Lonowski Feb 13 '13 at 19:28
  • I raised [the issue](https://github.com/isaacs/npm/issues/3155). So far, no answer. Thanks – Miguel Madero Feb 13 '13 at 22:31