TypeError: con.connect is not a function

I trying to connect PostgreSQL to Glitch, where I stored my backend.

my db.js file code:

const { Pool } = require(‘pg’);

const pool = new Pool({
host: process.env.PGHOST,
database: process.env.PGDATABASE,
username: process.env.PGUSER,
password: process.env.PGPASSWORD,
port: 5432,
ssl: ‘require’,
connection: {
options: project=${process.env.ENDPOINT_ID},

module.exports = {pool};

my user.controller.js file have a function:

const {pool} = require(‘…/…/services/db’);

async function checkIfUserExists(email) {
const existUser = await pool.query(getUserByEmail, [email]);

return existUser.rows;

This function checkIfUserExists returns TypeError: con.connect is not a function.

Please help me to deal with that.

where is the code that has the actual con.connect reference? can you tell what it expects con to be there? and see if you can find out where the con value comes from.

I change connection to

const { Pool } = require(‘pg’)

const pool = new Pool({
connectionString: “URL” + “?sslmode=require”,

pool.connect((err) => {
if (err) throw err
console.log(“Connect to PostgreSQL successfully!”)

module.exports = pool

now everything is ok.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.