Created
February 3, 2011 10:33
-
-
Save nordringrayhide/809323 to your computer and use it in GitHub Desktop.
Access to Postgres with node.js
This file contains hidden or 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
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