我对节点pg模块发疯了,收到“已经有太多客户端”错误。
app.js例如,我的文件管理着一些路由,在这些路由中我查询了一些数据到postgres。app.js看起来像下面这样:
//First I create a client
var client = new pg.Client(connectionString);
// Then I use that client to every routes, for example:
ContPg.prototype.someController = function(req, res){
client.connect(function(error){
if(error) return console.error('error conectando', error);
// Need to close client if there's an error connecting??
client.query(someQuery, function(e,r){
client.end();
// Here sometimes I dont end client if i need to query more data
if(e) return console.error('error consultando', e);
// Do anything with result...
})
});
}
Run Code Online (Sandbox Code Playgroud)
就像我说过的那样,我将该文件的所有路由都使用该客户端pg.js,但是在具有其他路由的其他文件中,我也这样做以连接到postgres(创建客户端并用于管理该文件的所有路由)
问题 …