I am trying to set up a database connection from my existing react app. But I am getting net.Socket is not a constructor error. I have seen this Node JS: net.Socket is not a constructor but still can't figure out what should I do. I have tried using websocket but then I am getting some other exception -websocket is not a constructor.
Here is my code
import { Client } from 'pg';
const app = express();
const query = 'SELECT id, description, name, salary FROM public.usecase_details';
const client = new Client({
user: 'out',
host: 'pgn.example.com',
database: 'salary_details',
password: 'out',
port: 1032,
});
client.connect();
client.query(query)
.then((res) => {
console.log('Table is found');
})
.catch((err) => {
console.error(err);
})
.finally(() => {
client.end();
});
Can I please get some idea/ help to solve this issue?

pg(full name: node-postgres) is a library meant for usage in a node.js environment. You cannot use it in the browser with react. You need an application server between the website and the database. How are you serving your html and js files?