JavaScript PostgreSQL libraries

Updated Nov 2026

JavaScript PostgreSQL libraries connect Node.js and serverless code to a PostgreSQL database and run SQL queries. A client keeps a pool of open connections and sends each query's values as parameters separate from the SQL text. These libraries let apps and backend services read and write relational data without opening a new database connection for every request.

Popularity

node-postgres has the most monthly downloads in this comparison, at 372.0M.

LibraryMonthly downloadsStarsLast releaseLicense
pg
372.0M
13.2KSep 2026MIT
postgres
145.4M
8.8KNov 2026Unlicense
@neondatabase/serverless
28.6M
557Nov 2026MIT
pg-promise
3.6M
3.5KNov 2026MIT
pg-native
1.3M
Not on GitHubSep 2026MIT
slonik
1.1M
Not on GitHubNov 2026BSD-3-Clause
@databases/pg
103.5K
Not on GitHubAug 2026MIT
serverless-postgres
80.2K
Not on GitHubMay 2025MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibrarySQL template tagManaged connection poolBuilt-in HTTPS queries
pgUnsupportedBuilt-inUnsupported
postgresBuilt-inBuilt-inUnsupported
@neondatabase/serverlessBuilt-inBuilt-inBuilt-in
pg-promiseUnsupportedBuilt-inUnsupported
pg-nativeUnsupportedUnsupportedUnsupported
slonikBuilt-inBuilt-inUnsupported
@databases/pgBuilt-inBuilt-inUnsupported
serverless-postgresUnsupportedUnsupportedUnsupported
Built-inNot supported

Libraries and code examples

Connects Node.js applications to PostgreSQL through query and connection APIs.

Downloads / mo
372.0M
Stars
13.2K
Last release
8.23.1
License
MIT

Strengths

  • Pools reusable connections. Use Pool for a shared set of database connections.
  • Caches named prepared statements. Name a query to reuse its plan on the same connection.

Limitations

  • Transactions need one checked-out client. Run all transaction statements on the same borrowed client.
  • Borrowed clients must be released. Return clients to the pool even after query errors.

Quickstart

From README.md
$ npm install pg@8.23.1
import { Client } from 'pg';
const client = new Client();
await client.connect();
console.log((await client.query('SELECT 1 AS one')).rows);
await client.end();

pg examples

From open-source projects on GitHub

Sends SQL template values separately through PostgreSQL protocol parameters.

Downloads / mo
145.4M
Stars
8.8K
Last release
4.1.1
License
Unlicense

Strengths

  • Binds values through tagged templates. Interpolate values in sql templates; the driver sends them separately.
  • Reserves connections for transactions. Use sql.begin to keep a transaction on its own connection.

Limitations

  • numeric and decimal return strings. Choose explicit parsing for numeric and decimal database values.
  • Undefined values are rejected. Pass null explicitly for missing values.

Quickstart

From README.md
$ npm install postgres@4.1.1
import postgres from 'postgres';
const sql = postgres();
console.log(await sql`SELECT 1 AS one`);
await sql.end();

postgres examples

From open-source projects on GitHub

@neondatabase/serverless

Runs PostgreSQL queries over HTTP or WebSockets in JavaScript runtimes.

Downloads / mo
28.6M
Stars
557
Last release
1.2.1
License
MIT

Strengths

  • Queries over HTTP requests. Use neon for one-shot queries through fetch.
  • Supports interactive transactions over WebSockets. Use Pool or Client for sessions and dependent transaction queries.

Limitations

  • HTTP batches are not interactive. Use WebSocket Pool or Client for session-dependent transactions.
  • Serverless pools need request-local cleanup. Create, use, and close WebSocket clients inside the same request handler.

Quickstart

From README.md
$ npm install @neondatabase/serverless@1.2.1
import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL);
console.log(await sql`SELECT 1 AS one`);

@neondatabase/serverless examples

From open-source projects on GitHub

pg-promise

Checks query results with methods named for the expected row count.

Downloads / mo
3.6M
Stars
3.5K
Last release
12.8.0
License
MIT

Strengths

  • Checks expected result row counts. Use result-specific methods to reject unexpected numbers of rows.
  • Reuses connections across related queries. Group related queries in task; use tx for automatic transactions.

Limitations

  • Brace placeholders conflict with templates. Keep those placeholders in ordinary strings instead of JavaScript template literals.

Quickstart

From Database.html
$ npm install pg-promise@12.8.0
import pgPromise from 'pg-promise';
const pgp = pgPromise();
const db = pgp(process.env.DATABASE_URL);
console.log(await db.one('SELECT 1 AS one'));
pgp.end();

pg-native

Connects to PostgreSQL through native libpq with synchronous and callback query interfaces.

Downloads / mo
1.3M
Last release
3.9.1
License
MIT

Quickstart

From README.md
$ npm install pg-native@3.9.1
const Client = require('pg-native');
const client = new Client();
client.connectSync();
console.log(client.querySync('SELECT 1 AS one'));
client.end();

Builds PostgreSQL queries from SQL tokens, with assertions and transaction scoping.

Downloads / mo
1.1M
Last release
49.13.0
License
BSD-3-Clause

Quickstart

From index.d.ts
$ npm install slonik@49.13.0
import { createPool, sql } from 'slonik';
const pool = await createPool(process.env.DATABASE_URL);
console.log((await pool.query(sql.unsafe`SELECT 1 AS one`)).rows);
await pool.end();

slonik examples

From open-source projects on GitHub

Runs SQL-tagged queries through a PostgreSQL connection pool with transaction scopes and streaming.

Downloads / mo
103.5K
Last release
6.1.0
License
MIT

Quickstart

From index.d.ts
$ npm install @databases/pg@6.1.0
import createConnectionPool, { sql } from '@databases/pg';
const db = createConnectionPool({ connectionString: process.env.DATABASE_URL });
console.log(await db.query(sql`SELECT 1 AS one`));
await db.dispose();

@databases/pg examples

From open-source projects on GitHub

serverless-postgres

Wraps a single pg client for serverless functions with connection retry and backoff.

Downloads / mo
80.2K
Last release
2.1.2
License
MIT

Quickstart

From README.md
$ npm install serverless-postgres@2.1.2
const ServerlessClient = require('serverless-postgres');
const client = new ServerlessClient({ connectionString: process.env.DATABASE_URL });
async function handler() {
  await client.connect();
  const result = await client.query('SELECT 1 AS one');
  await client.clean();
  return result.rows;
}
module.exports.handler = handler;

serverless-postgres examples

From open-source projects on GitHub

FAQ

node-postgres suits general Node.js apps that want explicit pool and client control. Postgres.js suits code that writes queries as tagged template literals. Neon serverless driver suits serverless and edge functions that query over HTTP or WebSockets.

The Neon serverless driver runs PostgreSQL queries over HTTPS or WebSockets from JavaScript runtimes. Its WebSocket mode offers a Pool and Client compatible with node-postgres.

Pool is the connection pool class in node-postgres. It keeps connections open and hands one to each query instead of connecting per request.

Slonik is a PostgreSQL client that builds queries from SQL tokens. It adds result assertions, transaction scoping, and schema validation of rows.

node-postgres uses parameterized query configs with an explicit pool and client lifecycle. Postgres.js writes queries as tagged templates with an automatically managed pool.

For coding agents

Found your PostgreSQL library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official