Knows Not Much
Knows Not Much

Reputation: 31546

global installation of npm modules on windows

I have installed node on my windows 8 machine and even if I install a module globally, my code cannot find the module.

C:\Windows\system32>npm -g install connect
[email protected] C:\Users\Abhishek\AppData\Roaming\npm\node_modules\connect
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected])

C:\Windows\system32>d:

D:\>cd myapps\todo

D:\myapps\todo>node server.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'connect'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (D:\myapps\todo\server.js:1:77)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

D:\myapps\todo>

I recollect that on a linux environment I had done sudo npm -g install connect and then my code was able to find the module.

So what is going wrong here?

Upvotes: 1

Views: 278

Answers (1)

Knows Not Much
Knows Not Much

Reputation: 31546

OK. I was able to solve this.

I had to set the NODE_PATH environment variable and point it to C:\Users\Abhishek\AppData\Roaming\npm\node_modules\

now it works perfectly.

Upvotes: 1

Related Questions