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?
if you are using windows , it takes some steps , 1) create a file called package.json
where hello is the name of the package and * means the latest version of your dependency
2) code to you project directory and run the following command
npm install
It installs the dependencies
if you are in the windows7 platform maybe you should change the NODE_PATH like this:
%AppData%\npm\node_modules
From my expierience with win8.1 npm installs modules on
C:\Users\[UserName]\AppData\Roaming\npm\node_modules
but dumply searches them onC:\Users\[UserName]\node_modules
.One simple solution reference module in application by full path:
Alternatively you could add to
~/.npmrc
right prefix. I've gotC:\Program Files\nodejs
for 64 Win7.For Windows 10, I had to locally install gulp in the folder:
C:\Users\myaccount\AppData\Roaming\npm\node_modules
This fixed my issue of "gulp is not recognized"
I had a terrible time getting global modules to work. Eventually, I explicitly added
C:\Users\yourusername\AppData\Roaming\npm
to the PATH variable under System Variables. I also needed to have this variable come before the nodejs path variable in the list.I am running Windows 10.