pg

Non-blocking PostgreSQL client for Node.js — pure JavaScript with optional native bindings.

pg

Node.js

Non-blocking PostgreSQL client for Node.js — pure JavaScript with optional native bindings.

Fit

Bundle (gzip)

25.2 kB

83.3 kB raw

Install size includes transitive dependencies. Bundle size is gzipped browser payload.

Freshness

The Problem

Talking to PostgreSQL from Node without an ORM means you still need reliable connection pooling, parameterized queries to prevent SQL injection, and proper handling of types and async results.

What It Does

pg (node-postgres) offers a clean client and connection pool, parameterized queries, cursors, and streaming. It is the de facto low-level PostgreSQL driver that most Node ORMs and query builders sit on top of.

Installation

bash
npm install pg

Usage Example

js
import { Pool } from "pg";

const pool = new Pool({ connectionString: process.env.DATABASE_URL });

const { rows } = await pool.query(
  "SELECT id, email FROM users WHERE active = $1",
  [true]
);

console.log(rows);

Related packages