question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: con.connect is not a function when calling Client.connect()

See original GitHub issue
import dbConfig from '../dbConfig';
const { Client } = require('pg');
module.exports = {
  query: async (text, params) => {
    const client = new Client(dbConfig);
    await client.connect();
    const res = await client.query(text, params);
    console.log(res)
  }
};

DB Config is:

{
  port: process.env.DB_PORT,
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  connectionTimeoutMillis:5000
}

Constantly prints TypeError: con.connect is not a function

I tried with several different databases, both local and hosted(I can connect to them through DBeaver) and all of the are giving me the same issue. Is it something wrong with my code?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vitaly-tcommented, Sep 28, 2020

You do not even have con.connect anywhere in your code example, which suggests the error happens elsewhere.

0reactions
brunolnettocommented, Nov 28, 2022

Warm compliments. I write a NodeJS app boilerplate. In case you are willing to further help, it is on repository https://github.com/web-needle/sappio

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: con.connect is not a function con ... - Stack Overflow
Everytime I use con on the first file it works, but not on the second one, unless I repeat the whole mysql.createConnection. My...
Read more >
TypeError: con.connect is not a function when calling Client ...
TypeError : con.connect is not a function when calling Client.connect()
Read more >
Node.js with MySQL - w3resource
It provides all most all connection/query from MySQL. ... You can terminate a connection by calling the end() method :
Read more >
db.query is not a function node js
pg_pconnect() opens a connection to a PostgreSQL database. It returns a connection resource that is needed by other PostgreSQL functions. If a second...
Read more >
Node.js and MySQL Complete Tutorial - CodeForGeek
In this Node js and MySQL tutorial, we are going to learn how to connect Node ... sqlMessage: 'Client does not support authentication...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found