Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Neon · Class

Pool

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.

How it works

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.

Syntax

new Pool(config)

Parameters

NameTypeDescription
configPool configurationConfiguration object containing the database connection details; the documented example supplies connectionString from DATABASE_URL.

Returns

A Pool instance that exposes the query and session/transaction functionality of the Neon serverless driver.

Key points

  • Its main capabilities are persistent sessions, interactive transaction support, and compatibility with the pg ecosystem.
  • The standard construction pattern passes the database URL through the connectionString option.
  • Queries are asynchronous and return a result from which rows can be destructured.

Example: Query with Pool

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.

When to use it

pg-compatible application code

An application uses node-postgres-compatible APIs while connecting through Neon’s serverless driver.

Interactive transactions and sessions

Several statements must share a session or transaction context.

Long-running server

A long-lived Node.js service needs a reusable WebSocket-backed database pool.

Interview questions

QWhat is Neon Pool used for?

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.

QHow do you execute a query with Pool?

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.

QWhy does Pool use WebSockets?

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.

  • Client
  • neon()
  • parseIntoClientConfig
  • node-postgres
  • WebSockets

Source: Neon serverless driver. Checked 2026-10-16.