I am learning nodejs at the moment on Windows. Several modules are installed globally with npm.cmd, and nodejs failed to find the installed modules. Take jade for example,
npm install jade -g
Jade is installed in directory "C:\Program Files (x86)\nodejs\node_modules"
, but the following code will fail with a "Cannot find module 'jade'"
error,
var jade = require('jade');
However, the code will run successfully when jade is locally installed (without -g option in npm). I don't want to use locally-installed modules, it's a waste of disk space for me, can someone help me to make the globally-installed modules work 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 (runcontrol.exe sysdm.cpl,System,3
).Quick solution in Windows 7+ is to just run:
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 yourPATH
, but withoutnode_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:
See similar question for more details: How do I install a module globally using npm?
Just download and re-install the node from this and this will fix all the path issues.
Don't forget to restart your command prompt or terminal.
To make it short, use
npm link jade
in your app directory.I ran into this issue on Windows 7, running
as administrator while being logged on as a normal user.
Solution: When executing the same installation as normal user (not "run as admin" for cmd) all was fine. I guess it is related to the default install and search path.
I stumbled on this question because I want to use node.js with visual studio 2015 on my new computer with windows 10. I used node.js on windows 7 and 8 and 8.1 Never a problem node.js finding a module. I use a legacy node.js 0.10.39 because I have to use this version because of the serial and RFXCOM module.
The answer for windows 10 is to set the NODE_PATH in the enviroment variables with C:\Users\User\node_modules.
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:
Important: only this without the
node_modules
part, took me half hour to see this.