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?

Wrikken
  • 69,272
  • 8
  • 97
  • 136
reza
  • 5,972
  • 15
  • 84
  • 126

1 Answers1

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.

djbrick
  • 213
  • 1
  • 4
  • 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 '13 at 04:17
  • should I not be doing : npm install pg -g for global? Or when do you use -g? – reza Sep 24 '13 at 04:18
  • it is recommended to install locally unless you need a binary to your $path variable see http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/ if you want to install it globally see http://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package – djbrick Sep 24 '13 at 19:58