Connect to Neon Postgres from a serverless function using the Neon HTTP driver

domain: neon.tech · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Install the Neon serverless driver: `npm install @neondatabase/serverless`.
  2. Import and configure the driver to use the HTTP transport (no TCP, works in edge runtimes): `import { neon } from '@neondatabase/serverless'; const sql = neon(process.env.DATABASE_URL);`
  3. Execute queries using the tagged template literal: `const rows = await sql`SELECT * FROM users WHERE id = ${userId}`;` — parameters are passed safely.
  4. For transactions, use `neonTransaction`: wrap multiple statements in `sql.transaction([...])` or use the `neon()` pool with WebSockets enabled for multi-statement transactions.
  5. Deploy to your edge runtime (Vercel Edge, Cloudflare Workers, etc.) and set `DATABASE_URL` as an environment secret in the platform's dashboard.

Known gotchas

Related routes

Enable and query the Neon Data API (PostgREST-compatible REST interface) with JWT auth and RLS
neon.tech · 6 steps · unrated
Create a database and Postgres role in a Neon project via API and rotate a role's credentials
neon.tech · 5 steps · unrated
Choose and construct the right Neon connection string: pooled (PgBouncer -pooler) vs direct, and fetch URIs via API
neon.tech · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans