Nodejs cannot find installed module on Windows Nodejs cannot find installed module on Windows windows windows

Nodejs cannot find installed module on Windows


Add an environment variable called NODE_PATH and set it to %USERPROFILE%\Application Data\npm\node_modules (Windows XP), %AppData%\npm\node_modules (Windows 7/8/10), or wherever npm ends up installing the modules on your Windows flavor. To be done with it once and for all, add this as a System variable in the Advanced tab of the System Properties dialog (run control.exe sysdm.cpl,System,3).

Quick solution in Windows 7+ is to just run:

rem for futuresetx NODE_PATH %AppData%\npm\node_modulesrem for current sessionset NODE_PATH=%AppData%\npm\node_modules

It's worth to mention that NODE_PATH is only used when importing modules in Node apps. When you want to use globally installed modules' binaries in your CLI you need to add it also to your PATH, but without node_modules part (for example %AppData%\npm in Windows 7/8/10).


Old story

I'm pretty much new to node.js myself so I can be not entirely right but from my experience it's works this way:

  1. -g is not a way to install global libraries, it's only a way to place them on system path so you can call them from command line without writing the full path to them. It is useful, for example, then node app is converting local files, like less — if you install it globally you can use it in any directory.
  2. node.js itself didn't look at the npm global dir, it is using another algorithm to find required files: http://nodejs.org/api/modules.html#modules_file_modules (basically its scanning every folder in the path, starting from the current for node_modules folder and checks it).

See similar question for more details: How do I install a module globally using npm?


I know i can awake a zombie but i think this is still a problem, if you need global access to node modules on Windows 7 you need to add this to your global variable path:

C:\Users\{USER}\AppData\Roaming\npm

Important: only this without the node_modules part, took me half hour to see this.


if you are in the windows7 platform maybe you should change the NODE_PATH like this:%AppData%\npm\node_modules