Registry / database / node-pg-connection-pool

node-pg-connection-pool

JSON →
library0.9.1jsnpmunverified

Connection pool for node-postgres built on top of generic-pool providing simplified query execution and raw connection management. Version 0.9.1 is the latest stable release. It supports ES6 features like Promises, Maps, and Sets, requiring Node >=4. The library offers a seamless interface for running queries without manually managing connections, while also allowing direct access to raw pg clients via acquire/release. It is configurable with pgOptions (for node-postgres client parameters) and poolOptions (for generic-pool configuration), and optionally supports native pg bindings. It is an alternative to other pooling solutions like pg-pool, but is less actively maintained.

npm install node-pg-connection-pool
INSTALL
IMPORT
SIG · NODE-PG-CONNECTION
N
node-pg-connection-pool
databasejavascriptv0.9.1
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.

PgPool
const PgPool = require('node-pg-connection-pool')
import PgPool from 'node-pg-connection-pool'
This package is CommonJS only; does not support ES modules natively.
PgPool
const { default: PgPool } = require('node-pg-connection-pool').default
No named exports; the module exports a single constructor function. Incorrect destructuring may cause undefined.
default
const PgPool = require('node-pg-connection-pool')
const { Pool } = require('node-pg-connection-pool')
The module exports a single default export, not named 'Pool'.

Shows creating a pool with custom configuration, running a parameterized query, and draining the pool.

const PgPool = require('node-pg-connection-pool'); // Create a pool with connection options const pool = new PgPool({ pgOptions: { host: process.env.PGHOST || 'localhost', port: parseInt(process.env.PGPORT || '5432', 10), database: process.env.PGDATABASE || 'test', user: process.env.PGUSER || 'postgres', password: process.env.PGPASSWORD || '' }, poolOptions: { min: 2, max: 10 } }); // Quick query using async/await async function run() { try { const result = await pool.query('SELECT $1::int AS number', [42]); console.log(result.rows); } catch (err) { console.error(err); } finally { pool.drain().then(() => pool.destroyAllNow()); } } run();
Debug
Known issues
gotchaPool.query returns rows directly, not the full result object like pg.Client.query
fix
Access result.rows for the rows array; other properties like command, rowCount are not available.
affects: >=0.x
gotcharelease() must be called exactly once per acquired client, otherwise pool leaks
fix
Use a try...finally block to ensure release() is called even on error.
affects: >=0.x
gotchaThe pool does not handle automatic reconnection; failed connections are not retried
fix
Implement application-level retry logic or use a more robust pool like pg-pool.
affects: >=0.x
deprecatedThe 'name' option for naming pools is not used internally
fix
Omit the name option; it has no behavior.
affects: >=0.x
deprecatedpgNative option requires installing pg-native, which often causes build issues
fix
Skip pgNative: true unless you really need native bindings and have build tools installed.
affects: >=0.x
gotchaPool.query does not support transactions; use acquire() to manage transactions manually
fix
Use pool.acquire(), then client.query('BEGIN'), etc., then release.
affects: >=0.x
Errors
Common errors & fixes
Cannot find module 'node-pg-connection-pool'
Package not installed or not in node_modules.
fix
Run 'npm install node-pg-connection-pool' in your project root.
TypeError: pool.query is not a function
Incorrect import or using wrong object (e.g., destructuring Pool).
fix
Use 'const PgPool = require("node-pg-connection-pool");' and instantiate with 'new PgPool(...)'.
Error: listen EADDRINUSE: address already in use :::5432
Another process (e.g., another pool or postgres instance) is using the port.
fix
Change the port in pgOptions or kill the other process.
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL server is not running or not accessible at that host/port.
fix
Start PostgreSQL service or check connection parameters.
Upgrade
Version history
0.9.1latest on npm
Audit
Dependencies
pgoptionalRequired for PostgreSQL communication; exports the Client class.
generic-poolrequiredUsed for underlying connection pool implementation.
Agent activity
5 hits · last 30 days
node
4
Resources