I m new in javascript and web developer, i want to connect to postgre database, so I use the following code
<!DOCTYPE html>
<html>
<head>
  <label id="Connected" >Waiting...</label>
</head>
  
  <body>
    <button  class="btn btn-success" onclick="connect()">Load Query</button>
  
  </body>
  <script>
    function connect()
    {
      const { Client } = require('pg');
      const client = new Client({
      user: 'postgres',
      host: 'localhost',
      database: 'helloworld',
      password: 'Mypostgres2021',
      port: 5432,
    })
  
    //   client.connect(function(err) {
    //   if (err) throw err;
    //   console.log("Connected!");
    // });
    
      document.getElementById("Connected").innerHTML = "Connected";
    }
  </script>
</html>
when I run the page I get the following error Uncaught "ReferenceError: require is not defined", I am using visual studio code.
I try to solve this error by installing pg from npm code, but I still get the error.
