Cannot connect local PostgreSQL DB
See original GitHub issueI connect my PostgreSQL local database in Node.js server using pg.
All worked fine, but suddenly it stopped to work.
This is my code:
const {Pool} = require('pg')
const connectionString = process.env.DATABASE_URL;
const ssl = process.env.NODE_ENV == 'production' ? '?ssl=true' : '';
const pool = new Pool({
connectionString: connectionString + ssl
});
const db = {
pool: pool,
test: async () => {
try {
console.log('before connection');
let result = await pool.query('SELECT $1::text as status', ['connected']);
console.log('connected')
return result.rows[0].status;
} catch (error) {
console.error('Unable to connect to the database:', error);
return null;
}
}
}
module.exports = db;
It stuck on pool.query. ‘before connection’ is logged, no error is thrown.
The very same code works fine with my remote db, and I can connect the local db with pgAdmin.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
You don’t need to downgrade Node, just upgrade pg to the latest version.
Duplicate of #2275