Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Accepted Answer
https://github.com/brianc/node-postgres/issues/2558#issuecomment-2575641839
I had to remove the ?sslmode=require from the database connection string
Here is working code
import dotenv from 'dotenv';
import pg from 'pg';
dotenv.config();
const { Pool } = pg;
// Decode the base64-encoded CA certificate
const caCert = process.env.DATABASE_CRT
? Buffer.from(process.env.DATABASE_CRT, 'base64').toString('utf-8')
: undefined;
// Configure SSL based on the environment
const sslConfig = process.env.ENVIRONMENT !== 'local' && caCert
? { rejectUnauthorized: true, ca: caCert }
: undefined;
// Create a new PostgreSQL connection pool
export const pool = new Pool({
connectionString: process.env.DATABASE_URL,
connectionTimeoutMillis: 5000,
ssl: sslConfig,
});
// Example function to test the connection
async function testConnection() {
try {
const client = await pool.connect();
console.log('Connected to the database successfully.');
client.release();
} catch (err) {
console.error('Database connection error:', err.stack);
}
}
// Run the test
testConnection();