使用node-postgres断开与数据库的连接

时间:2019-02-25 12:16:15

标签: node.js postgresql node-postgres

我遇到node-postgres的问题,有时我失去了与PG的连接。为了找回它,我总是需要重启服务器。

下面是代码段:

const pg = require('pg');

let connectionString;

if (process.env.NODE_ENV === 'production') {
  connectionString = 'postgres://USER:PASSWORD@HOST:PORT/DB';
} else {
  connectionString = 'postgres://USER:PASSWORD@HOST:PORT/DB';
}

const pool = new pg.Pool({
  connectionString: connectionString,
})

有人可以帮助我吗?我不知道为什么。

0 个答案:

没有答案
相关问题