Nodejs postgresql connexion issue

Hello,
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: ${config.host}`);

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

    client.query(query)
        .then(res => {
            const rows = res.rows;

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

            process.exit();
        })
        .catch(err => {
            console.log(err);
        });
}

I get an error :
image
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