© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4mo ago•
1 reply
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
DATABASE_URL
uses port
5432
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: { ... }
})
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
DATABASE_URL
is on port
6543
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);
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?
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Failed to connect to postgres
SupabaseSSupabase / help-and-questions
3w ago
Supabase postgres() & createClient() connection both in the same node server
SupabaseSSupabase / help-and-questions
3y ago
Error trying to connect to postgres_changes in realtime
SupabaseSSupabase / help-and-questions
5mo ago
Supabase Realtime in long-running Node.js — is manual channel re-subscription required?
SupabaseSSupabase / help-and-questions
2mo ago