Framework guides
Connect with Node.js
Use node-postgres with pooling, TLS, and safe shutdown.
5 minute read ยท Updated September 2026Install and configure
pnpm add pg
pnpm add -D @types/pgCreate one shared pool
import { Pool } from "pg";
export const db = new Pool({
connectionString: process.env.DATABASE_URL,
max: 10,
connectionTimeoutMillis: 5_000,
idleTimeoutMillis: 30_000,
ssl: { rejectUnauthorized: true },
});Application behavior
- Create one pool per application process, not per request.
- Use parameterized queries.
- Release checked-out clients in finally blocks.
- Close the pool during graceful shutdown.
- Keep the combined pool size of all replicas below the role connection limit.
Was this guide useful?
Get helpIf anything is unclear or incorrect, tell the support team.