Registry / database / pgpass

pgpass

JSON →
library1.0.5jsnpmunverified

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 pgpass
INSTALL
IMPORT
SIG · PGPASS
P
pgpass
databasejavascriptv1.0.5
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.

default
import pgPass from 'pgpass'
const { default: pgPass } = require('pgpass'); // wrong if no default export assumed
The module exports a function as default. In CommonJS, use require('pgpass') which returns the function directly.
pgPass
const pgPass = require('pgpass')
const pgPass = require('pgpass').default // will fail because there is no .default
CommonJS require returns the function directly, not an object with default property.
pgPass
import pgPass from 'pgpass'
import * as pgPass from 'pgpass' // will import an object, but the default is a function
The module is not an ES module; using import * creates a module namespace object, not the function. Use default import instead.

Reads .pgpass file and retrieves password for given host and user, then uses it to connect.

const pgPass = require('pgpass'); const connInfo = { host: 'pgserver', user: 'the_user_name' }; pgPass(connInfo, function(pass) { connInfo.password = pass; // now connect to PostgreSQL console.log('Password:', connInfo.password); }); // With options (no de-escape) const options = {}; pgPass(connInfo, options, function(pass) { console.log('Password (raw):', pass); });
Debug
Known issues
gotchaReturns undefined if PGPASSWORD environment variable is set (to prevent double use)
fix
Unset PGPASSWORD or use a different method if you need pgpass to read the file.
affects: >=1.0.0
gotchaOn non-Windows systems, the .pgpass file must not be readable or writable by group or others, otherwise returns undefined
fix
Set file permissions to 0600: chmod 0600 ~/.pgpass
affects: >=1.0.0
deprecatedCallback style is deprecated; prefer Promises or async/await via util.promisify
fix
Use const pgPassPromise = require('util').promisify(require('pgpass'));
affects: >=1.0.0
gotchaES module import fails because the package is CommonJS-only; using import in Node.js requires default interop
fix
Use require() or enable esModuleInterop in TypeScript and use import pgPass from 'pgpass'
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: pgPass is not a function
Using import * as pgPass from 'pgpass' gives an object instead of the function.
fix
Use import pgPass from 'pgpass' (with esModuleInterop) or const pgPass = require('pgpass').
undefined is not a function
Passing options incorrectly: pgPass(connInfo, callback) but accidentally swapped arguments.
fix
Ensure callback is last argument: pgPass(connInfo, callback) or pgPass(connInfo, options, callback).
ENOENT: no such file or directory, open '/home/user/.pgpass'
The .pgpass file does not exist.
fix
Create the file with correct permissions: touch ~/.pgpass && chmod 600 ~/.pgpass
module not found: 'pgpass'
Package not installed.
fix
Install: npm install pgpass
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
split2requiredUsed to split the pgpass file lines
Agent activity
2 hits · last 30 days
node
2
Resources
packagepgpass
pgpass — npm install pgpass · libregistry