The code crashes at the query object creation.
var conString = "postgres://mydbusr:thepassword@localhost/mydb";
var client = new pg.Client(conString);
client.connect(function(err) {
if (err) {
return console.error('could not connect to postgres', err);
}
var query = client.query('SELECT id FROM people'); //THE PROBLEM IS HERE
query.on('row', function(row) {
//Do something
});
client.end();
});
And this is the errror that I really don't understand:
events.js:72
throw er; // Unhandled 'error' event
^
Error: Connection terminated
at null.<anonymous> (/liveupdates/node_modules/pg/lib/client.js:184:29)
at g (events.js:180:16)
at EventEmitter.emit (events.js:92:17)
at Socket.<anonymous> (/liveupdates/node_modules/pg/lib/connection.js:66:10)
at Socket.EventEmitter.emit (events.js:95:17)
at TCP.close (net.js:466:12)