Build failed when installing node-postgres module for node.js

I'm very (very) new to node.js, and also fairly green when it comes to server side configuration and coding. (I have a long history of client-side programming, most recently with Adobe Flex and ActionScript.)

Anyhow, I asked Rackspace (who manages a Linux server for me) to install node.js and node-postgres.

From the comments in the ticket, that installation went like this:


node.js

Running Transaction
  Installing     : nodejs-stable-release                             [1/1] 

Installed: nodejs-stable-release.noarch 0:5-3
Complete!

and node-postgres

[root@237175-web2 src]# npm install pg  

npm http GET https://registry.npmjs.org/pg  
npm http 200 https://registry.npmjs.org/pg  
npm http GET https://registry.npmjs.org/pg/-/pg-0.6.17.tgz  
npm http GET https://registry.npmjs.org/generic-pool/1.0.9  
npm http 200 https://registry.npmjs.org/generic-pool/1.0.9  
npm http GET https://registry.npmjs.org/generic-pool/-/generic-pool-1.0.9.tgz  

 pg@0.6.17 install /usr/src/node_modules/pg  
 node-waf configure build || (exit 0)

Checking for program g++ or c++          : /usr/bin/g++   
Checking for program cpp                 : /usr/bin/cpp   
Checking for program ar                  : /usr/bin/ar   
Checking for program ranlib              : /usr/bin/ranlib   
Checking for g++                         : ok    
Checking for node path                   : not found   
Checking for node prefix                 : ok /usr   
Checking for program pg_config           : /usr/bin/pg_config   
'configure' finished successfully (0.051s)  
Waf: Entering directory `/usr/src/node_modules/pg/build'  
[1/2] cxx: src/binding.cc -> build/Release/src/binding_1.o  
[2/2] cxx_link: build/Release/src/binding_1.o -> build/Release/binding.node  
Waf: Leaving directory `/usr/src/node_modules/pg/build'  
'build' finished successfully (0.745s)  
pg@0.6.17 ./node_modules/pg  
+-- generic-pool@1.0.9  

More info:

[root@237175-web2 ~]# ls -la /usr/src/node_modules/pg  
total 68  
drwxr-xr-x 9 root root 4096 Apr 26 22:34 .  
drwxr-xr-x 3 root root 4096 Apr 26 22:34 ..  
drwxr-xr-x 2 root root 4096 Apr 26 22:34 benchmark  
drwxr-xr-x 4 root root 4096 Apr 26 22:34 build  
drwxr-xr-x 3 root root 4096 Apr 26 22:34 lib  
-rw-r--r-- 1 root root 5618 Apr 26 22:34 .lock-wscript  
-rw-r--r-- 1 root root 1269 Feb 23 23:58 Makefile  
drwxr-xr-x 3 root root 4096 Apr 26 22:34 node_modules  
-rw-r--r-- 1 root root   21 Mar  3 15:19 .npmignore  
-rw-r--r-- 1 root root  962 Apr 26 22:34 package.json  
-rw-r--r-- 1 root root 6843 Mar 27 09:30 README.md  
drwxr-xr-x 2 root root 4096 Apr 26 22:34 script  
drwxr-xr-x 2 root root 4096 Mar 21 23:37 src  
drwxr-xr-x 5 root root 4096 Apr 26 22:34 test  
-rw-r--r-- 1 root root  990 Feb 23 23:58 wscript  
[root@237175-web2 ~]#  

A little “Hello world” node.js example works fine (hooray!), but a simple Postgres example fails on the require('pg') statement, saying that the module cannot be found. I've looked on the server and can't find a pg.js file anywhere.

Any clue as to why the node-postgres build failed?

Install it globally:

npm install -g pg

You may need to become root, e.g. with

sudo npm install -g pg