{"library":"postgres-pool","title":"Postgres Connection Pool","description":"postgres-pool is a robust connection pooling library for Node.js applications designed to interact with PostgreSQL databases via the `node-pg` client. As of its current stable version, 11.0.4, it offers an actively maintained and feature-rich alternative to the original `pg-pool`, addressing specific reliability concerns such as connection timeouts that were observed in its predecessor. The library features enhanced error handling, graceful cluster failover mechanisms, and streamlined integration with AWS RDS through a simplified `ssl='aws-rds'` configuration option for secure connections. It adheres to a modern development paradigm, being built with TypeScript to enforce type safety and primarily utilizing Promises, moving away from callback-based patterns. The project typically sees frequent patch releases and major version increments roughly annually, with a significant v11 update in late 2025 transitioning `pg` to a peer dependency. It strives for API compatibility with `pg-pool` to ease migration for existing users.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install postgres-pool"],"cli":null},"imports":["import { Pool } from 'postgres-pool';","import { Pool, PoolClient } from 'postgres-pool';","import { QueryResult } from 'pg';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Pool } from 'postgres-pool';\n\n// Use environment variables for sensitive connection details in production.\n// For local development, replace with your actual database credentials.\nconst pool = new Pool({\n  connectionString: process.env.DATABASE_URL ?? 'postgres://username:pwd@127.0.0.1/db_name',\n  max: 20, // max number of clients in the pool\n  idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed\n});\n\nasync function getUser(userId: number) {\n  try {\n    const results = await pool.query('SELECT id, name, email FROM \"users\" WHERE id=$1', [userId]);\n    if (results.rows.length > 0) {\n      console.log('User found:', results.rows[0]);\n      return results.rows[0];\n    } else {\n      console.log('User not found.');\n      return null;\n    }\n  } catch (err) {\n    console.error('Error executing query', err);\n    throw err;\n  }\n}\n\n// Example usage:\ngetUser(42);\n\n// Ensure the pool is gracefully shut down when the application exits\nprocess.on('SIGINT', async () => {\n  console.log('Shutting down database pool...');\n  await pool.end();\n  console.log('Database pool shut down.');\n  process.exit(0);\n});","lang":"typescript","description":"Demonstrates initializing a PostgreSQL connection pool and executing a simple SELECT query with automatic connection release, including error handling and graceful shutdown.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}