SupabaseS
Supabase2mo ago
ken

Connect to Postgres in a long-running node server

Hi, I'm using drizzle ORM and my backend is a long-running (not serverless) node server. How should I connect? This is how I currently do it, where DATABASE_URL uses port
5432
and no query parameters:

import { drizzle } from 'drizzle-orm/node-postgres'
import { Pool } from 'pg'
import { env } from '../../shared/env'

const pool = new Pool({ connectionString: env.DATABASE_URL })

export const db = drizzle(pool, {
    schema: { ... }
})


However, I see that the drizzle example does this instead (where DATABASE_URL is on port 6543 with no query parameters:

import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

const client = postgres(process.env.DATABASE_URL, { prepare: false })
const db = drizzle(client);


What is the optimal way to connect to the database in a non-serverless environment?
Was this page helpful?