144

I'm not 100% sure, but I believe I installed node v5 from the windows installer on both my home and office PCs.

On my home PC global installs happen under %APPDATA%:

(dev) go|c:\srv> which lessc
c:\users\bjorn\appdata\roaming\npm\lessc
c:\users\bjorn\appdata\roaming\npm\lessc.cmd

while on my office PC, they go under program files:

(dev) go|w:\srv> which lessc
c:\program files\nodejs\lessc
c:\program files\nodejs\lessc.cmd

I need to provide the full path to a number of these global tools to PyCharm's file watcher, and since the project file i shared it would make sense to not have global resources under a user folder.

Why would the global installs end up in different folders, and how can I force them to a location that is common to all team members?

thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • 1
    3 years later, I had a similar mystery. The answer turned out to be that node had created a junction at c:\program files\nodejs, which actually pointed to %appdata%\nvm\v8.10.0. So it gave the illusion that might fit what you saw. – John Hatton Jun 11 '18 at 15:58
  • 1
    The c:\program files\nodejs symlink turned out to be an artifact of [nvm](https://github.com/coreybutler/nvm-windows) – John Hatton Jun 11 '18 at 17:17

7 Answers7

94

According to: https://docs.npmjs.com/files/folders

  • Local install (default): puts stuff in ./node_modules of the current package root.
  • Global install (with -g): puts stuff in /usr/local or wherever node is installed.
  • Install it locally if you're going to require() it.
  • Install it globally if you're going to run it on the command line. -> If you need both, then install it in both places, or use npm link.

prefix Configuration

The prefix config defaults to the location where node is installed. On most systems, this is /usr/local. On windows, this is the exact location of the node.exe binary.

The docs might be a little outdated, but they explain why global installs can end up in different directories:

(dev) go|c:\srv> npm config ls -l | grep prefix
; prefix = "C:\\Program Files\\nodejs" (overridden)
prefix = "C:\\Users\\bjorn\\AppData\\Roaming\\npm"

Based on the other answers, it may seem like the override is now the default location on Windows, and that I may have installed my office version prior to this override being implemented.

This also suggests a solution for getting all team members to have globals stored in the same absolute path relative to their PC, i.e. (run as Administrator):
(Run this in cmd, not in PowerShell!)

mkdir %PROGRAMDATA%\npm
setx PATH "%PROGRAMDATA%\npm;%PATH%" /M
npm config set prefix %PROGRAMDATA%\npm

open a new cmd.exe window and reinstall all global packages.

Explanation (by lineno.):

  1. Create a folder in a sensible location to hold the globals (Microsoft is adamant that you shouldn't write to ProgramFiles, so %PROGRAMDATA% seems like the next logical place.
  2. The directory needs to be on the path, so use setx .. /M to set the system path (under HKEY_LOCAL_MACHINE). This is what requires you to run this in a shell with administrator permissions.
  3. Tell npm to use this new path. (Note: folder isn't visible in %PATH% in this shell, so you must open a new window).
m93a
  • 8,866
  • 9
  • 40
  • 58
thebjorn
  • 26,297
  • 11
  • 96
  • 138
74

These are typical npm paths if you install a package globally:

Windows XP -             %USERPROFILE%\Application Data\npm\node_modules
Newer Windows Versions - %AppData%\npm\node_modules
or -                     %AppData%\roaming\npm\node_modules
Dennis Stücken
  • 1,296
  • 9
  • 10
  • 1
    Hmm.. `%APPDATA%` is under a user folder, and PyCharm doesn't seem to accept environment variables, so I guess this is a no-go then. – thebjorn Nov 12 '16 at 00:15
  • 9
    this is wrong fix your answer ~/AppData/Roaming/npm/node_modules $ npm /c/Users/Phil/AppData/Roaming/npm/npm: line 12: node: command not found – Philip Rego Dec 28 '17 at 15:17
  • From installing the package globally through Powershell, a generic file, a `cmd_auto_file` file and a `Windows PowerShell Script` file was created in `"$env:APPDATA\npm"` – Olov Dec 30 '20 at 11:01
26

Just press windows button and type %APPDATA% and type enter.

Above is the location where you can find \npm\node_modules folder. This is where global modules sit in your system.

Subhan Luckiest
  • 293
  • 3
  • 3
  • 1
    If you look at my question you'll find that your assertion is false. The global modules can also be installed under `%PROGRAMFILES%\nodejs`, which is my first question (why do they end up in different folders on my home/office PCs?). The context of my question (as is stated..) is that I need to provide the path to these globally npm installed tools to the PyCharm IDE, in order for other team members to benefit from me setting it up correctly for our projects. Since (a) PyCharm doesn't allow env vars when specifying executable, and (b) `%APPDATA%=c:\Users\bjorn\..` I can't use APPDATA here. – thebjorn Apr 13 '17 at 17:09
5

As of today, global packages installed like for eg. npm i -g @vue/cli are by default store in a directory:

C:\Users\<YourUserName>\AppData\Roaming\npm\node_modules
1

If you're just trying to find out where npm is installing your global module (the title of this thread), look at the output when running npm install -g sample_module

$ npm install -g sample_module C:\Users\user\AppData\Roaming\npm\sample_module -> C:\Users\user\AppData\Roaming\npm\node_modules\sample_module\bin\sample_module.js + sample_module@5.1.0 updated 1 package in 2.821s

java-addict301
  • 3,220
  • 2
  • 25
  • 37
  • The question is the entire question, not just the title. I don't think this is an answer to my question. – thebjorn Apr 16 '19 at 18:47
  • 1
    @thebjorn I don't think your question title is specific enough, and hence people like me will find it who are looking for the npm install location, not looking for how to change it or why there are different folders, etc. – java-addict301 Apr 16 '19 at 19:05
  • 1
    The accepted answer contains the answer to your question: `npm config ls -l | grep prefix`, and even if it didn't, the correct procedure would be to ask a new more narrowly focused question... – thebjorn Apr 17 '19 at 04:55
  • 1
    Definitely not easier, since you have to install something instead of just look something up (which makes it unusable e.g. for shell/bat scripts). – thebjorn Apr 17 '19 at 13:26
  • 1
    It is if you're trying to figure out where your global modules are being put during installs (like as was my case and probably others' who will find this question based on its current title). – java-addict301 Apr 17 '19 at 13:38
  • 1
    Again, that's your question (which is better solved by the `where` command), it is not what this question is about. This is not an answer to my question. – thebjorn Apr 17 '19 at 13:46
  • I found my answer helpful and I hope others will as well (given the broad title of the OP's question).. – java-addict301 Apr 22 '19 at 12:27
  • 1
    Of course you found your answer helpful to _your_ question ("where did npm -g install a package on _my_ machine"). That is an entirely different question however, and you should delete this answer, ask that as a new question, and self-answer it. Adding random facts to a 3+ year old question is not the right thing to do. Also, _all_ of the 3 previous answers mention the `%APPDATA%` path, so you're not even adding anything new..? – thebjorn Apr 22 '19 at 14:51
-1

here is how I install react globally on windows,

npm install -g react

and I can see package installed at,

C:\Users\username\AppData\Roaming\npm\node_modules

Mayur
  • 9
  • 1
-1

I install node v14.9.0 using nvm and I find it in the D drive: D:\Users\<user_name>\AppData\Roaming\nvm\v14.9.0\node64.exe.

Mike
  • 57
  • 1
  • 5