Nodejs postgresql connexion issue

Very beginner in javascript, I am working with nodejs environnment.
I try to connect to postgreql to exexcute a query and finally display the result in html page.
here is the js part :

const pg = require('pg') ;

const config = {
	host: process.env.PGHOST,
	user: process.env.PGUSER,
	password: process.env.PGPASSWORD,
	database: process.env.PGDATABASE,
	port: process.env.PGPORT
	} ;
const client = new pg.Client(config) ;

client.connect(err => {
    if (err) throw err;
    else { queryDatabase(); }

function queryDatabase() {
    console.log(`Running query to PostgreSQL server: ${}`);

    const query = 'SELECT sum(nb_cas) FROM tbl'

        .then(res => {
            const rows = res.rows;

   => {
                console.log(`Read: ${JSON.stringify(row)}`);

        .catch(err => {

I get an error :
After reading many posts and answers I don’t really undersand, I know that it is a connexion issue but can’t solve it alone.
Thanks for help