Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I just installed node-postgres by running npm install pg .

In my source code, I added var pg = require('pg"); and when I run I now get

module.js:340
    throw err;
          ^
Error: Cannot find module 'pg'
    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> (/Users/rrazavipour-lp/Documents/workspace/Astute/app.js:9:10)
    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 Module.runMain [as _onTimeout] (module.js:497:10)

What step am I missing?

share|improve this question
 
This might help... ls /usr/local/lib/node_modules/ express npm pg prettyjson soap –  reza Sep 23 at 23:46

1 Answer

up vote 1 down vote accepted

Where is the node_modules folder in relation to your application?

from http://nodejs.org/api/modules.html:

If the module identifier passed to require() is not a native module, and does not begin with '/', '../', or './', then node starts at the parent directory of the current module, and adds /node_modules, and attempts to load the module from that location.

share|improve this answer
 
it is only showing up in /usr/local/lib/node_modules –  reza Sep 24 at 4:11
 
then either copy it to the same directory your code is running from or run npm install from the directory your code is running from. –  djbrick Sep 24 at 4:17
 
should I not be doing : npm install pg -g for global? Or when do you use -g? –  reza Sep 24 at 4:18
 
it is recommended to install locally unless you need a binary to your $path variable see blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation if you want to install it globally see stackoverflow.com/questions/15636367/… –  djbrick Sep 24 at 19:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.