← Docs
Express
One connection module, any route handler. Middleware-friendly — attach to req or import directly.
Install
npm install goldlapel pg
# or: npm install goldlapel postgres
# or: npm install goldlapel @vercel/postgres Gold Lapel is a driver-agnostic wrapper — install whichever Postgres driver your app uses alongside it. pg is the most common; postgres (postgres.js) and @vercel/postgres also work.
Setup
Create a connection module at db.js:
import * as goldlapel from 'goldlapel';
import pg from 'pg';
const gl = await goldlapel.start(process.env.DATABASE_URL);
const pool = new pg.Pool({ connectionString: gl.url });
export { gl, pool }; Route Handler
Import the connection and query directly:
import { pool } from './db.js';
app.get('/users', async (req, res) => {
const result = await pool.query('SELECT * FROM users');
res.json(result.rows);
}); Middleware Pattern
Attach the connection to req for use in any downstream handler:
import { pool } from './db.js';
app.use((req, res, next) => {
req.db = pool;
next();
}); ORMs
Using Prisma? See @goldlapel/prisma. Using Drizzle? See @goldlapel/drizzle.