node-postgres

Non-blocking PostgreSQL client for Node.js with pure JavaScript and native libpq bindings.

Library
npm
v8.23.0
13,212 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
78 /100 Good
Development Activity 84
Maintenance 44
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
82 /100 Excellent
Architecture 85
Code Quality 82
Innovation 80
Learning Curve 82

node-postgres (published to npm as pg) is the de facto PostgreSQL client for Node.js, providing both a pure JavaScript driver and optional native libpq bindings behind a single, consistent API. It implements the PostgreSQL wire protocol directly, so connecting, querying, and streaming results require no external client library beyond Node.js itself.

The project ships as a monorepo of focused packages — pg for the core client and connection pool, pg-cursor for server-side cursors, pg-query-stream for streaming large result sets, and pg-protocol for the low-level wire-protocol parser/serializer — so applications can pull in only what they need. With roughly 36 million weekly downloads, it underpins the majority of Node.js applications, ORMs, and query builders that talk to PostgreSQL.

What You Get

  • A Client and Pool implementation with automatic connection pooling and configurable overflow/timeout behavior
  • A pure-JS wire-protocol implementation (pg-protocol) plus optional native libpq bindings (pg-native) behind the identical API
  • Extensible type parsing so PostgreSQL types (arrays, JSON, timestamps, custom domains) coerce to native JS values
  • Streaming helpers (pg-cursor, pg-query-stream) for iterating large result sets without loading them fully into memory
  • Support for parameterized queries, named/prepared statements with plan caching, and async LISTEN/NOTIFY notifications

Common Use Cases

  • Powering the database layer of Express/Fastify/Koa APIs that talk directly to PostgreSQL
  • Serving as the underlying driver for higher-level tools like Knex, Sequelize, and Drizzle ORM
  • Running on edge/serverless runtimes (Cloudflare Workers, Deno, Bun) via the pg-cloudflare transport and pure-JS client
  • Streaming and paginating very large query results with pg-cursor or pg-query-stream for reporting/export jobs

Under The Hood

Architecture - node-postgres is organized as a Lerna/Yarn-workspaces monorepo split by concern: pg-protocol implements the raw PostgreSQL wire protocol (message parsing/serialization) independent of any transport; lib/connection.js wraps a TCP/TLS socket (lib/stream.js) and speaks that protocol; lib/client.js layers query/parameter handling and the DatabaseError type on top of a Connection; and pg-pool wraps Client to add pooling, exposed to consumers as the top-level Pool/Client API in lib/index.js. Companion packages (pg-cursor, pg-query-stream) subclass the same Client/Query primitives to add streaming, and the native binding (lib/native) is lazy-loaded behind a native property so the pure-JS and libpq paths share one public surface.

Tech Stack - The core pg package is plain CommonJS JavaScript (published with a matching ESM wrapper in esm/) with runtime dependencies on pg-connection-string, pg-pool, pg-protocol, pg-types, and pgpass; the optional pg-native peer dependency and pg-cloudflare optional dependency add libpq bindings and an edge-runtime transport respectively. The monorepo is built and tested with Lerna, Yarn workspaces, and Vitest/Mocha, targets Node.js >= 16, and TypeScript appears only in the dev/tooling chain, not the published library surface.

Code Quality - Test coverage is extensive and segmented by concern: test/unit, test/integration, test/native, test/cloudflare, and test/tls under packages/pg/test, plus a test/integration/gh-issues directory of regression tests tied to specific bug reports. CI runs on every push (GitHub Actions badge in the README). The codebase favors small, single-purpose modules (client.js, connection.js, query.js, result.js) with consistent naming, though the library does not ship its own TypeScript type definitions — consumers rely on the community-maintained @types/pg package.

API Design - The public API is deliberately small: new Pool(config) or new Client(config) followed by .query(text, values) covers most use cases, with the native and pure-JS clients sharing an identical interface so switching transports requires no code changes. Prepared statements, LISTEN/NOTIFY, and COPY TO/FROM are exposed through the same query-shaped API rather than bespoke methods, keeping the surface area low. Documentation is centralized at node-postgres.com with a companion GitHub wiki cataloguing community “Extras,” though the type-definition gap adds minor friction for TypeScript users.

Used by 147 apps in this directory

Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

39,975

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 6 days ago
TypeScript
60%
AGPL 3.0

Puter

Developer Tools · File Storage

43,605

A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.

View details
88
Repo Health
88
Technical
70
Dependency
Built with
TypeScript 60%
JavaScript 36%
Updated 6 days ago
TypeScript
95%
MIT

qm

AI Agents · AI Assistants · Automation

15,266

An open-source, multiplayer agent harness that gives every employee and every room in a company its own scoped memory, sandbox, and AI agent — in Slack and on the web.

View details
80
Repo Health
88
Technical
84
Dependency
Built with
TypeScript 95%
Updated 1 weeks ago
Java
93%
Apache 2.0

QuestDB

Analytics · Databases

17,360

A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.

View details
91
Repo Health
86
Technical
67
Dependency
Built with
Java 93%
Updated 6 days ago
TypeScript
96%
Apache 2.0

rakazo

AI Agents · AI Assistants

3,009

An open-source platform for persistent AI teammates that own their own conversations, memory, routines, and computers — self-hosted, model-agnostic, and available on web, desktop, and mobile.

View details
80
Repo Health
91
Technical
83
Dependency
Built with
TypeScript 96%
Updated 6 days ago
TypeScript
95%
AGPL 3.0

Rallly

Scheduling

5,277

Self-hostable group scheduling polls that eliminate back-and-forth emails and find the best meeting time for everyone.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 95%
Updated 1 weeks ago
Go
39%
Apache 2.0

Rill

Analytics · Data Engineering

2,914

The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.

View details
87
Repo Health
88
Technical
64
Dependency
Built with
Go 39%
TypeScript 38%
Svelte 21%
Updated 1 weeks ago
Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,195

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
86
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 1 weeks ago
TypeScript
97%
AGPL 3.0

Rybbit

Analytics

13,069

Open-source, privacy-friendly web and product analytics with cookieless tracking, session replays, funnels, and real-time dashboards — a self-hostable alternative to Google Analytics.

View details
86
Repo Health
85
Technical
68
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers