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

Neon · Module

Pool.end

Pool.end() closes a Neon serverless driver's WebSocket pool after its work is complete. Await it during cleanup, especially when the pool is created within a request handler.

How it works

Pool.end() closes the Neon serverless driver's WebSocket pool and should be awaited after the pool's work is complete. In request-scoped runtimes, create and close the pool within the same request so the connection does not outlive the handler.

Syntax

await pool.end();

Returns

A promise that resolves when the pool has been closed.

Key points

  • Pool.end() applies to the WebSocket-based Pool constructor, not the driver's HTTP query function.
  • A pool can remain open across multiple operations that require session or transaction behavior, then be closed with end().
  • The documented usage awaits pool.end() after querying, establishing the normal cleanup order.

Example: Close a Neon pool

import { Pool } from '@neondatabase/serverless';

const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const { rows } = await pool.query('SELECT 1');
await pool.end();
console.log(rows);

Creates a WebSocket-backed pool, runs a query, and closes the pool when finished.

When to use it

Close the pool before the request ends

Request-scoped edge handler

Release pool resources during shutdown

Node.js service using Pool

Finish WebSocket-based database work cleanly

Interactive transaction or session

Interview questions

QWhat does Pool.end() do?

Pool.end() shuts down the pool after its queries have completed. Awaiting it ensures cleanup finishes before the surrounding operation ends.

Follow-up: Why might Pool be unsuitable for a single stateless query? The HTTP query interface avoids managing a persistent pool, while Pool is intended for sessions, interactive transactions, or node-postgres compatibility.

QHow does Pool.end() relate to the Neon serverless driver's connection mode?

Neon's Pool uses WebSockets and is compatible with the node-postgres Pool API. Calling end closes that pool's resources after use.

Follow-up: When should a pool be created per request? In edge runtimes where WebSocket connections cannot outlive a request, create, use, and close it inside the handler.

QWhen should application code call Pool.end()?

The pool should be closed after the final query or transaction has completed, typically with await pool.end(). This prevents a request-scoped WebSocket pool from remaining open.

Follow-up: What alternative fits a one-statement, stateless operation? Use the driver's HTTP-based neon function rather than a WebSocket Pool.

  • Pool
  • Client
  • neon()
  • @neondatabase/serverless

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