Created
November 5, 2012 16:28
-
-
Save danhigham/4018125 to your computer and use it in GitHub Desktop.
Node PG example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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