A lightweight library for implementing hierarchical tree structures in PostgreSQL using closure tables. Current stable version 1.1.3 (last updated 2020). It provides an intuitive API for building, querying, and manipulating tree data, including adding nodes, inserting in specific positions, moving subtrees, and viewing the tree hierarchy. Differentiators include automatic table creation, a chainable builder API, and support for flexible tree operations without requiring raw SQL. Unlike ORM-based solutions, it offers a focused, minimal interface for tree structures, but it ties directly to pg Pool configuration via environment variables. Release cadence is low (sporadic); development appears to be in maintenance mode.
npm install postgres-treeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a tree table, adds a root and child node, retrieves leaf nodes, then destroys the table.
Check if table exists before calling build() if you want to preserve data.
Set required environment variables or wrap the constructor with your own Pool instance.
Fork the package or use a different library if custom connection parameters are needed.
Use ESM import or named import { PostgresTree }.Change to: const PostgresTree = require('postgres-tree').default;Ensure await tree.build() is called before performing any tree operations.
Run: npm install pg