Registry / database / node-postgres

node-postgres

JSON →
library0.6.2jsnpmunverified

node-postgres is a pure JavaScript PostgreSQL client for Node.js. Current version 0.6.2 is an early release with basic client, pool, SSL, and transaction support. It is unopinionated and low-level, requiring manual BEGIN/COMMIT/ROLLBACK for transactions. Unlike `pg` (the popular PostgreSQL client), this package has few features and is likely experimental or a simple wrapper.

npm install node-postgres
INSTALL
IMPORT
SIG · NODE-POSTGRES
N
node-postgres
databasejavascriptv0.6.2
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
const { Client } = require('node-postgres');
const Client = require('node-postgres').Client;
CommonJS only: package does not support ESM or TypeScript.
Pool
const { Pool } = require('node-postgres');
const { Pool } = require('pg-pool');
Pool is exported directly from 'node-postgres', not a separate package.
Client and Pool
const { Client, Pool } = require('node-postgres');
const client = require('node-postgres').Client;
Standard destructured import for both classes.

Connect to PostgreSQL, run a query, and close the connection using Client.

const { Client } = require('node-postgres'); (async () => { const client = new Client({ user: 'postgres', host: '127.0.0.1', database: 'test', password: process.env.DB_PASSWORD ?? 'password', port: 5432 }); await client.connect(); const res = await client.query('SELECT NOW()'); console.log(res.rows[0]); await client.end(); })().catch(console.error);
Debug
Known issues
gotchaAlways release client back to pool after checkout to avoid leaks.
fix
Use try/finally: const client = await pool.connect(); try { /* queries */ } finally { client.release(); }
affects: >=0.6.0
gotchaTransactions must use the same client; do not use pool.query for transactions.
fix
Checkout a client from pool, execute BEGIN/COMMIT/ROLLBACK manually, then release.
affects: >=0.6.0
gotchaSSL configuration requires key and cert as strings (read from files via fs.readFileSync).
fix
Pass ssl: { key: fs.readFileSync('path').toString(), cert: fs.readFileSync('path').toString() }.
affects: >=0.6.0
Errors
Common errors & fixes
Error: connect ENOENT /tmp/.s.PGSQL.5432
Default connection tries Unix socket; host/port not specified correctly.
fix
Set host: '127.0.0.1' and port: 5432 explicitly in Client/Pool config.
Error: Client was closed and is not queryable
Trying to run query on a client after client.end() or pool.end() has been called.
fix
Ensure queries are made before calling end(). Use a single client per transaction.
Error: Pool is not defined
Importing Pool incorrectly: using require('pg-pool') vs 'node-postgres'.
fix
Use const { Pool } = require('node-postgres');
Upgrade
Version history
0.6.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
node-postgres — npm install node-postgres · libregistry