Node.js for some reason cannot connect to postgresql -
the code crashes @ 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 postgres', err); } var query = client.query('select id people'); //the problem here query.on('row', function(row) { //do }); client.end(); });
and errror don't understand:
events.js:72 throw er; // unhandled 'error' event ^ error: connection terminated @ null.<anonymous> (/liveupdates/node_modules/pg/lib/client.js:184:29) @ g (events.js:180:16) @ eventemitter.emit (events.js:92:17) @ socket.<anonymous> (/liveupdates/node_modules/pg/lib/connection.js:66:10) @ socket.eventemitter.emit (events.js:95:17) @ tcp.close (net.js:466:12)
you forgot, pretty calls database asynchronous.
in code closed connection using
client.end();
without waiting, queries , respective responses have been processed.
Comments
Post a Comment