@neondatabase/serverless is a PostgreSQL driver optimized for serverless and edge environments (e.g., Vercel Edge, Cloudflare Workers) from Neon.tech. At version 0.5.3 (beta), it offers two APIs: a simple `neon` function for one-shot queries over HTTPS fetch, and Pool/Client for sessions/transactions via WebSockets. It is a drop-in replacement for the popular `pg` package (node-postgres) with message pipelining for low latency. It ships TypeScript types and is ESM-only. Key differentiators: works in edge runtimes without Node.js TCP, supports SQL template tag injection safety, and integrates tightly with Neon's serverless Postgres offering.
npm install neon-serverlessNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to set up and use the `neon` function for a simple one-shot query with SQL template tag safety and TypeScript.
Use dynamic import or switch to ESM in your project (set `"type": "module"` in package.json).
Create, use, and close Pool/Client inside the request handler. Do not store them globally.
Replace `arrayMode: true` with `fullResults: true` in the options object.
Use import { Pool, Client, neon } from '@neondatabase/serverless' instead of from 'pg'.For transactions, use `import { Pool } from '@neondatabase/serverless'` and wrap queries in `BEGIN`/`COMMIT`.Change to dynamic import: `const { neon } = await import('@neondatabase/serverless');` or set `"type": "module"`.Install the `ws` package and set `NeonConfig.webSocketConstructor = WebSocket;` before creating Pool/Client.
Move the `new Pool()` call inside the request handler and close it before returning.