You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PostgreSQL supports a [.pgpass](https://www.postgresql.org/docs/current/libpq-pgpass.html) file for storing passwords. The file is located at `~/.pgpass` on Unix systems and `%APPDATA%\postgresql\pgpass.conf` on Windows. Each line in the file has the format:
6
+
7
+
```
8
+
hostname:port:database:username:password
9
+
```
10
+
11
+
You can use the [pgpass](https://www.npmjs.com/package/pgpass) module together with the `password` callback to look up passwords from your `.pgpass` file:
12
+
13
+
```js
14
+
importpgfrom'pg'
15
+
importpgpassfrom'pgpass'
16
+
17
+
const { Pool } = pg
18
+
19
+
constpool=newPool({
20
+
user:'my-user',
21
+
host:'localhost',
22
+
database:'my-db',
23
+
password: (config) => {
24
+
returnnewPromise((resolve, reject) => {
25
+
constconnection= {
26
+
host:config.host,
27
+
port:config.port,
28
+
database:config.database,
29
+
user:config.user,
30
+
}
31
+
pgpass(connection, (password) => {
32
+
resolve(password)
33
+
})
34
+
})
35
+
},
36
+
})
37
+
```
38
+
39
+
The `password` option accepts an async function (or a function that returns a `Promise`). It is called with the connection parameters, so you can pass them directly to `pgpass` for lookup.
'Client.queryQueue is deprecated and will be removed in pg@9.0.'
21
21
)
22
22
23
-
constpgPassDeprecationNotice=nodeUtils.deprecate(
24
-
()=>{},
25
-
'pgpass support is deprecated and will be removed in pg@9.0. '+
26
-
'You can provide an async function as the password property to the Client/Pool constructor that returns a password instead. Within this function you can call the pgpass module in your own code.'
0 commit comments