pg-compatible application code
An application uses node-postgres-compatible APIs while connecting through Neon’s serverless driver.
Neon · Class
Neon’s Pool class provides a WebSocket-based connection pool for the serverless driver. Use it for interactive transactions, sessions, or node-postgres compatibility rather than ordinary stateless queries.
Pool is the WebSocket-based Neon serverless-driver class for applications that need node-postgres compatibility, sessions, or interactive transactions. Construct it with a connection string, use its query API, and close it when the application or request lifecycle ends.
new Pool(config)| Name | Type | Description |
|---|---|---|
config | Pool configuration | Configuration object containing the database connection details; the documented example supplies connectionString from DATABASE_URL. |
A Pool instance that exposes the query and session/transaction functionality of the Neon serverless driver.
import { Pool } from '@neondatabase/serverless';
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const { rows } = await pool.query('SELECT * FROM posts ORDER BY id');
await pool.end();
console.log(rows);Creates a Neon WebSocket pool, runs a query, prints the returned rows, and closes the pool.
An application uses node-postgres-compatible APIs while connecting through Neon’s serverless driver.
Several statements must share a session or transaction context.
A long-lived Node.js service needs a reusable WebSocket-backed database pool.
Pool is the Neon serverless driver's WebSocket-based class for session-oriented database access. It also provides compatibility with node-postgres, including its familiar pool-based usage.
Follow-up: When should HTTP be preferred? Use the driver's HTTP query function for stateless, single-statement operations; use Pool when sessions or interactive transactions are required.
Instantiate Pool with a configuration object containing the database connection string, then call its query method to execute SQL. The returned result includes rows, as shown in the official example.
Follow-up: What lifecycle step is required after use? Call the pool's close/end operation so its WebSocket resources are released.
Pool communicates over WebSockets rather than the driver's HTTP transport. This makes it appropriate for interactive transactions, sessions, and node-postgres compatibility.
Follow-up: What edge-runtime constraint matters? A WebSocket cannot survive the request, so create, use, and close the pool during that request.
Clientneon()parseIntoClientConfignode-postgresWebSockets