我有以下代码。
var express = require('express');
var app = express();
var path = require('path');
var pg = require('pg');
var conString = "postgres://user:password@endpoint:5432/StudentRecords";
//this initializes a connection pool
//it will keep idle connections open for a (configurable) 30 seconds
//and set a limit of 20 (also configurable)
var client = new pg.Client(conString);
client.connect(function(err) {
if(err) {
return console.error('could not connect to postgres', err);
}
else{
console.log("asdfaf")
}
});
client.connect();
它显示无法连接到postgres。但是当我尝试使用
从终端连接时psql --host=endpoint --port=5432 --username xxxxx --password --dbname=StudentRecords
我可以连接。为什么代码不起作用?我得到的错误是:
could not connect to postgres [Error: Connection terminated]