0

I'm using Windows.

I've installed mongodb module using next command:

npm install -g mongodb

mongodb module is listed when I type:

npm ls -g

But when I'm trying to do require('mongodb'); Node gives me an Error: Cannot find modue 'mongodb'. When I include mongodb with absolute path it's included fine:

require('C:\\Users\\Evgeniy\\AppData\\Roaming\\npm\\node_modules\\mongodb');

Any ideas what I'm doing wrong?

Cake_Seller
  • 338
  • 2
  • 14
  • Solution: Linux. On a more serious note. Why would you install mongodb globally rather than having it on your project? – majidarif Nov 03 '14 at 09:54
  • @majidarif I'm learning MongoDB at the moment and I thought it would be nice to have possibility to include it from anywhere. Maybe you right and I should install it locally. But any way I'm wondering why it doesn't work. I suppose I'm doing everything right. – Cake_Seller Nov 03 '14 at 09:59
  • @majidarif btw also I have coffee-script installed globally and it's either not available globally :( Strange thing – Cake_Seller Nov 03 '14 at 10:01
  • You need to add an env_variable. Check this post: http://stackoverflow.com/questions/9587665/nodejs-cannot-find-installed-module-on-windows – Nico Napoli Nov 03 '14 at 10:03

2 Answers2

1

Well, this must be caused by environment variables. You have to set NODE_PATH to C:\Users\Evgeniy\AppData\Roaming\npm\node_modules.

majidarif
  • 16,924
  • 14
  • 79
  • 127
0

You can run following commmand from command prompt:
setx NODE_PATH %APPDATA%\npm\node_modules

This will set the environment variable permanently in your user profile's environment settings

AIyer
  • 106
  • 1
  • 7