Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created November 5, 2012 16:28
Show Gist options
  • Save danhigham/4018125 to your computer and use it in GitHub Desktop.
Save danhigham/4018125 to your computer and use it in GitHub Desktop.
Node PG example
/*
* GET home page.
*/
var pg = require('pg');
exports.index = function(req, res){
var conString = "tcp://127.0.0.1/postgres";
var out = "";
client = new pg.Client(conString);
client.connect();
var query = client.query("SELECT NOW() as when");
query.on('row', function(row) {
out = row.when;
console.log(out);
});
query.on('end', function() {
client.end();
res.render('index', { title: out, envvars: process.env.VCAP_SERVICES });
res.end();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment