🗄️
Database300K+/wkUnlicense

postgres

Postgres.js is the fastest full-featured PostgreSQL client for Node.js and Deno, using tagged template literals for safe, readable queries. The library provides

Installation

npm
npm install postgres
yarn
yarn add postgres
pnpm
pnpm add postgres

Import

ESM
import postgres from 'postgres';

Quick Example

usage
import postgres from 'postgres';

const sql = postgres(process.env.DATABASE_URL);

const users = await sql`SELECT * FROM users WHERE active = true`;
const [user] = await sql`
  INSERT INTO users (name, email)
  VALUES (${'Alice'}, ${'[email protected]'})
  RETURNING *
`;

About postgres

Postgres.js is the fastest full-featured PostgreSQL client for Node.js and Deno, using tagged template literals for safe, readable queries. The library provides a simple API where the connection is also the query function: const users = await sql`SELECT * FROM users WHERE id = ${id}`. This tagged template approach automatically handles parameter binding, type serialization, and SQL injection prevention while keeping queries readable as plain SQL. Postgres.js supports connection pooling, prepared statements, realtime notifications (LISTEN/NOTIFY), transactions, savepoints, large objects, COPY for bulk operations, and dynamic query building through sql() fragments that can be composed safely. The library handles automatic type conversion between PostgreSQL and JavaScript types, including JSON, arrays, timestamps, and custom types. Postgres.js supports both ESM and CommonJS imports and provides full TypeScript types with generic query result typing. The library achieves exceptional performance through its custom protocol implementation and efficient memory management. Postgres.js is gaining rapid adoption as a modern alternative to pg, particularly for new projects that appreciate its cleaner API and use of tagged template literals for safe SQL composition.

Quick Facts

Packagepostgres
CategoryDatabase
Weekly Downloads300K+
LicenseUnlicense
Installnpm install postgres

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.