did you initialize the client with the current parameters? make sure you upload only a specific code portion where the error occurs instead of copying and pasting the full code. try
const { Pool } = require('pg');
const pool = new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT || 5432
});
pool.connect((err, client, release) => {
if (err) {
console.error('Error connecting to the database:', err.stack);
} else {
console.log('Successfully connected to database');
}
});
before registering a new user, try checking if it already exists and sanitize the inputs first.