UnhandledPromiseRejectionWarning: Error: Client has already been connected. You cannot reuse a client. code example
Example: Error: Client has already been connected. You cannot reuse a client.
- var client = new pg.Client(connection);
-
function test() {
+ var client = new pg.Client(connection);
+
client.connect(err => {
if (err) {
console.log(err);
return;
}
client.query('select 123', [], (err, data) => {
if (err) {
console.log(err);
} else {
console.log('DATA:', data.rows[0]);
}
client.end();
});
});
}