Non-blocking PostgreSQL client for Node.js written in TypeScript, currently at v2.0.4. Supports both ESM and CommonJS modules. Key differentiators include built-in types, pipeline queries, extensible value model, and hybrid query result objects (iterable both synchronously and asynchronously). Has no runtime dependencies, but requires Node >=18 and @types/node peer dependency. Actively maintained on GitHub with regular releases. Compared to alternatives like `pg`, it offers TypeScript-first design and binary result data format.
npm install ts-postgresNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to PostgreSQL using environment variables or defaults, executes a parameterized query, and streams results asynchronously.
Upgrade Node.js to version 18 or later.
Either iterate using `for await (const row of client.query(...))` or use `const result = await client.query(...); // To get full result`
Use `for await (const row of result)` and `result.columns` instead.
Explicitly read environment variables or use a configuration helper to map them to the config object.
Use named import: `import { connect } from 'ts-postgres'`Verify the hostname in configuration is correct and network is reachable. Increase connection timeout if needed.
Add `"type": "module"` to package.json or use CommonJS require syntax: `const { connect } = require('ts-postgres')`