Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

549
Views
Why is node-postgres (pg) hanging when I call client.connect()?

I recently had to upgrade my node.js version for my vue.js application (node.js on the backend) from v13.5.0 to v14.5.0. I reinstalled all my node packages, upgrading the ones I had to upgrade, and now the application hangs on all DB calls. We are using pg (node-postgres) for our database calls. I upgraded pg to version 7.18.2.

Our initialization code looks like this:

constructor() {
  this.pg = require('pg');
  this.client = null;
  this.initPromise = null;
}

async init() {
  if (!this.initPromise) {
    this.client = new this.pg.Client({
      application_name: 'Back end',
      ssl: {
        rejectUnauthorized: false
      }
    });
    this.initPromise = this.client.connect();
  }
  return this.initPromise;
}

async query(query, params) {
  await this.init();
  return await this.client.query(query, params);
}

I put console logs around the call to this.init() as follows:

console.log('before');
await this.init();
console.log('after');

'after' never prints out.

Does anyone know why it hangs now that I've upgrade my node version?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

It seems that pg v.8.3.0 solves this problem. I got v7.18.2 from running npm install pg. Seems that doesn't always install the latest version. npm install pg@latest does the trick.

over 4 years ago · Santiago Trujillo Report

0

@gib65 upgrading to v.8.3.0 did the trick for me too was banging my head on await and async. thought i was being a n00b again...

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!