Skip to content

Instantly share code, notes, and snippets.

@nordringrayhide
Created February 3, 2011 10:33
Show Gist options
  • Save nordringrayhide/809323 to your computer and use it in GitHub Desktop.
Save nordringrayhide/809323 to your computer and use it in GitHub Desktop.
Access to Postgres with node.js
var pg = require("pg");
pg.connect('pg://postgres:password@localhost:5432/postgres', function(err, client) {
if (err) { console.log(err) ; } else {
client.query("select tablename from pg_tables;", function(err, result) {
if (err) {console.log(err)} else
{ for (var i=0; i < result.rows.length; i++) { console.log(result.rows[i].tablename) }
}
});
}
})
/*
$ node node_postgres_test.js
=>
pg_type
pg_attribute
pg_statistic
sql_features
sql_implementation_info
sql_languages
sql_packages
pg_database
pg_authid
sql_parts
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment