Read .pgpass files to retrieve PostgreSQL passwords. Version 1.0.5 is the current stable release. The module reads the ~/.pgpass file (or Windows equivalent) and returns the matching password for a given connection configuration. It handles environment variables like PGPASSFILE and PGPASSWORD, and respects file permissions. This module is included in node-postgres but can be used standalone. The package has a low release cadence, with the last update years ago. It is stable and simple, focused solely on parsing pgpass files.
npm install pgpassNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Reads .pgpass file and retrieves password for given host and user, then uses it to connect.
Unset PGPASSWORD or use a different method if you need pgpass to read the file.
Set file permissions to 0600: chmod 0600 ~/.pgpass
Use const pgPassPromise = require('util').promisify(require('pgpass'));Use require() or enable esModuleInterop in TypeScript and use import pgPass from 'pgpass'
Use import pgPass from 'pgpass' (with esModuleInterop) or const pgPass = require('pgpass').Ensure callback is last argument: pgPass(connInfo, callback) or pgPass(connInfo, options, callback).
Create the file with correct permissions: touch ~/.pgpass && chmod 600 ~/.pgpass
Install: npm install pgpass