Registry / database / srieding-node-postgres

srieding-node-postgres

JSON →
library1.0.0jsnpmunverified

Non-blocking PostgreSQL client for Node.js. Pure JavaScript with optional native libpq bindings. Current stable version is 8.x. Supports parameterized queries, prepared statements, connection pooling, COPY operations, LISTEN/NOTIFY, and extensible type coercion. Key differentiators: same API for both pure JS and native bindings, lightweight abstractions, and a monorepo with modular packages (pg, pg-pool, pg-cursor, pg-query-stream, pg-connection-string, pg-protocol).

npm install srieding-node-postgres
INSTALL
IMPORT
SIG · SRIEDING-NODE-POST
S
srieding-node-postgres
databasejavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
import { Client } from 'pg'
const { Client } = require('pg')
CJS require works too, but ESM import is preferred. TypeScript types are included.
Pool
import { Pool } from 'pg'
const { Pool } = require('pg-pool')
Pool is re-exported from 'pg'. Direct 'pg-pool' import is legacy.
QueryResult
import { QueryResult } from 'pg'
import { QueryResult } from 'pg/lib/query'
Don't import from internal paths; types are exported from main entry.

Creates a connection pool, executes a simple query, and logs the result rows, then closes the pool.

import { Pool } from 'pg'; const pool = new Pool({ connectionString: process.env.DATABASE_URL ?? 'postgresql://user:password@localhost:5432/mydb' }); const res = await pool.query('SELECT NOW()'); console.log(res.rows); await pool.end();
Debug
Known issues
breakingIn pg@8, the default value for 'ssl' changed from false to 'prefer' when connecting via environment variables.
fix
Explicitly set ssl: false in config if you do not want SSL.
affects: >=8.0.0
deprecatedpg.Client constructor with string argument is deprecated. Use object with connectionString or config properties.
fix
new Client({ connectionString: '...' })
affects: >=8.0.0
gotchaPool.query() returns a Promise, but does NOT return the client to the pool if query throws after connection established.
fix
Use pool.query() correctly; ensure error handling does not accidentally hold client.
affects: *
gotchaParameters in parameterized queries are passed as an array, not as separate arguments.
fix
pool.query('SELECT $1::text', ['hello']) correct; pool.query('SELECT $1::text', 'hello') WRONG.
affects: *
deprecatedpg@7.x: `pg.defaults.ssl` is deprecated. Use per-instance ssl config.
fix
Set ssl on each Client or Pool instance.
affects: >=7.0.0 <8.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL server not running or wrong host/port.
fix
Start PostgreSQL or set correct host/port in connection string.
Error: password authentication failed for user "postgres"
Wrong password or user not allowed.
fix
Check password in connection string or pg_hba.conf settings.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
pg-nativeoptionalOptional native libpq bindings for performance
Agent activity
14 hits · last 30 days
node
10
Meta
2
OpenAI (training)
1
Resources
srieding-node-postgres — npm install srieding-node-postgres · libregistry