postgres

Postgres.js is a zero-dependency PostgreSQL client for Node.js, Deno, Bun, and Cloudflare Workers built on ES6 tagged template literals.

Library
npm
v3.4.9
8,722stars
Unlicense

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
67/100Good
Development Activity56
Maintenance52
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
86/100Excellent
Architecture88
Code Quality85
Innovation90
Learning Curve80

Postgres.js (published to npm as postgres) is a PostgreSQL client that implements the Postgres wire protocol directly in JavaScript, with no runtime dependencies at all. Queries are written as ES6 tagged template literals, so parameters are automatically extracted and sent to the server separately from the SQL text — safe by construction rather than by convention, with no separate escaping step to remember.

Beyond basic querying, it ships connection pooling, prepared statements, transactions with savepoints, LISTEN/NOTIFY, a subscribe() API that speaks Postgres’s logical replication protocol for real-time row-level change feeds, large object support, and a full custom-type system. A single source tree is transpiled to separate builds for Node (ESM and CommonJS), Deno, and Cloudflare Workers, so the same API works across all four runtimes.

It’s widely used as the low-level driver underneath higher-level tools — Drizzle ORM ships a first-class postgres-js adapter, for example — as well as directly in application code that wants raw SQL without an ORM in between.

What You Get

  • A connection pool with automatic reconnection, idle timeouts, and configurable max lifetime per connection
  • Tagged-template queries (sql\…`) with automatic parameterization, plus .unsafe()` for raw SQL and dynamic query building helpers
  • Transactions via sql.begin() with nested savepoint support and automatic rollback on thrown errors
  • LISTEN/NOTIFY support and a subscribe() API implementing logical replication for real-time insert/update/delete streams
  • Prepared statements, large object (largeObject) support, and a custom-type registration system for user-defined Postgres types
  • Single codebase transpiled to Node.js (ESM + CJS), Deno, Bun, and Cloudflare Workers builds via transpile.*.js scripts

Common Use Cases

  • Direct SQL in application code - teams that want typed, parameterized SQL without adopting a full ORM’s abstraction layer
  • Driver underneath an ORM or query builder - projects using Drizzle ORM’s postgres-js adapter or similar tools that need a fast, dependency-free Postgres transport
  • Real-time change feeds - services using sql.subscribe() against logical replication to react to row-level inserts/updates/deletes without polling
  • Edge and serverless deployments - Cloudflare Workers or other constrained runtimes where a zero-dependency, small-footprint driver avoids bundling a large dependency tree
  • Multi-runtime libraries - packages that need one Postgres client that behaves identically across Node.js, Deno, and Bun

Under The Hood

Architecture The library is organized around a small set of focused modules: index.js builds the sql tagged-template function and owns the connection-pool state machine (queues for connecting/open/busy/full/closed/reserved/ended connections, each a Queue from queue.js), connection.js (over 1,000 lines) implements the actual wire-protocol state machine — parsing and writing the Postgres binary message format via the tiny binary-builder in bytes.js — and dispatches to query.js, types.js, and subscribe.js for query lifecycle, type encode/decode, and logical-replication parsing respectively. Pool state transitions (move(c, queue)) are explicit and centralized, and higher-level features like begin() (transactions/savepoints) and reserve() (dedicated connections) are built as thin orchestration on top of the same connection/queue primitives rather than separate subsystems, which keeps one mental model for how a query ultimately reaches a socket.

Tech Stack Runtime dependencies are zero — the package.json declares no dependencies at all, only Node’s built-in net, tls, crypto, fs, os, and perf_hooks modules are used, meaning the wire protocol (startup, auth including SCRAM and MD5, simple/extended query, COPY, logical replication) is hand-implemented rather than delegated to a lower-level driver. Publishing is multi-target: transpile.cjs, transpile.deno.js, and transpile.cf.js each rewrite the ESM src/ tree into a CommonJS build, a Deno-compatible build, and a Cloudflare Workers (workerd) build, wired up via package.json’s exports map so consumers get the right build per runtime automatically. TypeScript users get hand-maintained .d.ts definitions under types/ rather than generated ones.

Code Quality Tests live in tests/index.js, a large single-file suite exercising real behavior against live Postgres instances (started via tests/bootstrap.js) rather than mocks, covering connection edge cases, all three auth methods, transactions/savepoints, LISTEN/NOTIFY, and type coercion; the same suite is re-run against the ESM, CJS, and Deno builds in CI. GitHub Actions runs the full matrix across nine Node versions (12 through 24) and six PostgreSQL versions (12 through 17) on every push, which is unusually thorough dependency-compatibility coverage for a library of this size. ESLint is configured and run as part of prepublishOnly, and error handling is explicit throughout — Postgres wire-level error fields are parsed into structured PostgresError objects with named properties (severity, code, detail, hint, position, etc.) rather than opaque strings.

What Makes It Unique Most Postgres clients in the Node ecosystem wrap libpq bindings or build on top of node-postgres; Postgres.js instead implements the wire protocol itself in plain JavaScript over raw sockets, which is what lets it ship with zero dependencies and run unmodified (after transpilation) on Deno, Bun, and Cloudflare Workers — runtimes where native bindings or node-postgres’s Node-specific assumptions don’t work. Combining that with first-class tagged-template query syntax, built-in logical-replication subscriptions, and savepoint-aware nested transactions in one cohesive API, rather than layering these as separate add-on packages, is the project’s distinguishing design choice.

Used by 29 apps in this directory

TypeScript
53%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,252

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
68
Dependency
Built with
TypeScript53%
Rust35%
Updated today
Rust
67%
MIT

Bun

Developer Tools

95,895

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust67%
C++19%
Updated yesterday
Swift
64%
GPL 3.0

cmux

Developer Tools · AI Development

26,845

A native, Ghostty-based macOS terminal with vertical tabs, agent-aware notifications, and a scriptable browser built for running many parallel AI coding agent sessions instead of juggling tmux panes.

View details
84
Repo Health
81
Technical
72
Dependency
Built with
Swift64%
Rust14%
Updated today
TypeScript
95%
AGPL 3.0

Docmost

Productivity · Note Taking · Collaboration

21,600

Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.

View details
89
Repo Health
70
Technical
70
Dependency
Built with
TypeScript95%
Updated yesterday
TypeScript
98%
Other

Dokploy

Devops · Hosting Control Panel · Security

37,130

Self-hosted PaaS that deploys apps and databases on your own VPS using Docker, Traefik, and multi-build-system orchestration

View details
88
Repo Health
76
Technical
64
Dependency
Built with
TypeScript98%
Updated 3 days ago
TypeScript
54%
MIT

FormBee

Forms Surveys

770

A self-hostable form backend that accepts HTML form submissions and routes them to email, Telegram, Discord, webhooks, and automation platforms — without writing any server-side code.

View details
29
Repo Health
48
Technical
70
Dependency
Built with
TypeScript54%
SCSS25%
HTML19%
Updated 1 years ago
TypeScript
61%
EPL-2.0

Huly Platform

Project Management · Team Chat · Collaboration

27,586

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
89
Repo Health
86
Technical
62
Dependency
Built with
TypeScript61%
Svelte34%
Updated 1 weeks ago
TypeScript
65%
Apache 2.0

Laminar

AI Development · Monitoring

3,230

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
85
Repo Health
76
Technical
69
Dependency
Built with
TypeScript65%
Rust33%
Updated yesterday
TypeScript
99%
AGPL 3.0

Manage

Project Management · Collaboration

70

Self-hosted, open-source project management with tasks, calendars, docs, and real-time team collaboration.

View details
41
Repo Health
57
Technical
71
Dependency
Built with
TypeScript99%
Updated 1 months 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

Search