I’m running my server from file (node) and after a few minutes, each and every time, I receive the following error:
node:events:505
throw er; // Unhandled ‘error’ event
^
Error: Connection terminated unexpectedly
at Connection. (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\client.js:132:73)
at Object.onceWrapper (node:events:641:28)
at Connection.emit (node:events:527:28)
at Socket. (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\connection.js:63:12)
at Socket.emit (node:events:539:35)
at TCP. (node:net:709:12)
Emitted ‘error’ event on Client instance at:
at Client._handleErrorEvent (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\client.js:341:10)
at Connection. (C:\Users\ryaan\Desktop\Code\ECom\node_modules\pg\lib\client.js:150:16)
at Object.onceWrapper (node:events:641:28)
[… lines matching original stack trace …]
at TCP. (node:net:709:12)
The code I’m using to connect is as follows (v basic):
const { Client } = require(‘pg’);
const connectionString = process.env.CONNECTION_STRING;
const client = new Client({
connectionString,
});
client.connect();
module.exports = client;
Does anyone know why the connection keeps dropping? Thanks