Config a node.js connector for postgresql

Note: since writing this post I have swithex (wholeheartedly) to using sss for all my node.js database connections (specifically mySQL, postgresql & mongoDB).

1) install ubuntu pg driver

apt-get install libpq-dev

2) npm install node.js pg driver

npm install pg

3) Install PG ORM Module

npm install orm

4) Test that the pg drivers works OK

var pg = require('pg'); 
//or native libpq bindings
//var pg = require('pg').native

//var conString = "tcp://postgres:1234@localhost/postgres";

var conString= "tcp://opengeo:opengeo@localhost/bmrg";

var client = new pg.Client(conString);
client.connect(function(err) {
  if(err) {
    return console.error('could not connect to postgres', err);
  client.query('SELECT NOW() AS "theTime"', function(err, result) {
    if(err) {
      return console.error('error running query', err);
    //output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)

Result should be like:

Mon Apr 15 2013 08:22:01 GMT+0000 (UTC)