PostgreSQL - Reconnect after lost Connection in Node.js

204 views
Skip to first unread message

Grant MacDonald

unread,
Jan 14, 2015, 6:20:08 PM1/14/15
to nod...@googlegroups.com
Hi folks.  I've built a small app using NodeJs and Express to pull data from an existing PostgreSQL DB using node-postgresql.  There will only be 1 or 2 users connected connected at a time so I have been using the Instance example instead of the Pooling example on the web site.  It is working great except I'm looking for a good example of how to handle when the connection to the PostgreSQL database is lost.  I would like to trap the error and then set a timer to try a reconnection later.  I am presuming that the "client.on('error', function... would be the way to do this.  Any suggestions or pointers appreciated on the best way to handle a lost database connection and keep the application running until a connection can be re-established.

Thanks. Grant.
Reply all
Reply to author
Forward
0 new messages