1

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?

1
  • This might help... ls /usr/local/lib/node_modules/ express npm pg prettyjson soap Commented Sep 23, 2013 at 23:46

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
should I not be doing : npm install pg -g for global? Or when do you use -g?
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/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.