Registry / database / pg-ssl

pg-ssl

JSON →
library0.0.1jsnpmunverified

A utility for parsing libpq-style environment variables into SSL configuration for node-postgres (pg). As of v0.0.1, it bridges a gap where node-postgres ignores SSL-related environment variables like PGSSLMODE, PGSSLROOTCERT, PGSSLCERT, and PGSSLKEY. It reads these env vars to produce the `ssl` object expected by `new Pool()`, including ca, cert, key, and rejectUnauthorized. Supports custom overrides, servername for SNI, and checkServerIdentity callback. Particularly useful for cloud SQL connections (e.g., Google Cloud SQL, AWS RDS) that require certificate-based TLS. Lightweight, no dependencies, and works with both ESM and CJS.

npm install pg-ssl
INSTALL
IMPORT
SIG · PG-SSL
P
pg-ssl
databasejavascriptv0.0.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.

parseSsl
import { parseSsl } from 'pg-ssl'
const parseSsl = require('pg-ssl')
Package does not have a default export; use named import or destructured require. CommonJS: const { parseSsl } = require('pg-ssl')

Demonstrates how to use parseSsl to configure SSL for a pg Pool, including optional servername override for cloud SQL.

import { Pool } from 'pg'; import { parseSsl } from 'pg-ssl'; const pool = new Pool({ // parseSsl reads PGSSLMODE, PGSSLROOTCERT, PGSSLCERT, PGSSLKEY from env // You can override any option by passing an object: ssl: parseSsl({ servername: 'my-project/my-sql-instance' }) }); pool.query('SELECT NOW()', (err, res) => { if (err) { console.error('Error executing query', err.stack); } else { console.log(res.rows[0]); } pool.end(); });
Debug
Known issues
gotchaparseSsl currently only supports 'disabled' as the only sslmode value; other modes like 'verify-ca' are not parsed and may require manual configuration.
fix
Manually set rejectUnauthorized and provide cert paths if using sslmode other than 'disabled'.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'pg-ssl'
Package not installed or import path incorrect.
fix
Run `npm install pg-ssl` and ensure your import uses the correct package name.
Property 'parseSsl' does not exist on type 'typeof import("pg-ssl")'
Trying to import default instead of named export.
fix
Use `import { parseSsl } from 'pg-ssl'` instead of `import parseSsl from 'pg-ssl'`.
UNABLE_TO_VERIFY_LEAF_SIGNATURE
SSL certificate chain incomplete or missing CA certificate.
fix
Set PGSSLROOTCERT to the CA certificate path and pass the path to parseSsl or set the env variable.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
packagepg-ssl
pg-ssl — npm install pg-ssl · libregistry