I am trying to run the following bit of code in node.js
to display the number of tables in a postgresql database:
var pg = require('pg');
var conString = "postgres://login:pwd@localhost/DB";
var client = new pg.Client(conString);
client.connect(function(err) {
if (err) {
console.error('Could not connect to DB', err);
} else {
console.log('Could connect to DB');
client.query("SELECT * FROM pg_catalog.pg_tables", function(err, result) {
if (err) {
console.error('Error with table query', err);
} else {
var cnt = result.rows.length;
console.log("Row count: " + cnt.toString());
}
});
console.log('After query');
client.end();
}
});
Unfortunately, only the following is displayed in the console:
Could connect to DB
After query
Why isn't the row count line displayed? How can I find out what the issue is?