【发布时间】:2020-11-02 15:55:54
【问题描述】:
我最近不得不将我的 vue.js 应用程序(后端的 node.js)的 node.js 版本从 v13.5.0 升级到 v14.5.0。我重新安装了所有节点包,升级了我必须升级的那些,现在应用程序挂起所有数据库调用。我们使用 pg (node-postgres) 进行数据库调用。我将 pg 升级到 7.18.2 版本。
我们的初始化代码如下所示:
constructor() {
this.pg = require('pg');
this.client = null;
this.initPromise = null;
}
async init() {
if (!this.initPromise) {
this.client = new this.pg.Client({
application_name: 'Back end',
ssl: {
rejectUnauthorized: false
}
});
this.initPromise = this.client.connect();
}
return this.initPromise;
}
async query(query, params) {
await this.init();
return await this.client.query(query, params);
}
我在 this.init() 调用周围放置控制台日志,如下所示:
console.log('before');
await this.init();
console.log('after');
'after' 永远不会打印出来。
有谁知道我升级节点版本后为什么会挂起?
【问题讨论】:
-
init方法不应该是async,因为您没有在其中使用await,但这与问题无关 -
您在哪里将连接详细信息和凭据传递给客户端?
-
您之前安装了哪个版本的 node-postgres?
-
根据 node-postgres 文档 (node-postgres.com/features/connecting),它从环境变量中获取连接详细信息。但是我尝试将它们显式传递给 Client 构造函数: this.client = new this.pg.Client({host: ..., database: ..., etc.});但无济于事。我之前安装了 7.8.0。
标签: node.js postgresql freeze node-postgres