使用localhost节点Project访问服务器上的数据库



我为我的网站购买了一个VPS。我用vue和node构建了一个小项目。在这篇文章中,我使用了在localhost上运行良好的postgresql。

我想将我的数据库从localhost更改为服务器数据库,在那里我安装了postgres并创建了数据库和表。

我的db.js文件如下:

const Pool = require('pg').Pool;
const pool = new Pool({
user: "postgres",
password: "root",
database: "todo_database",
host:"45.111.241.15",
port: 5432
});
module.exports = pool;

然后我尝试从localhost vue页面发送表单数据,它给出了以下错误:

error connecting db Error: connect ECONNREFUSED 45.111.241.15:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '45.111.241.15',
port: 5432   

我对这个问题以及如何解决这个问题不太了解。你能指导我如何连接我的服务器数据库吗?

我遵循以下步骤,它起了作用:

编辑/etc/postgresql/9.1/main/postgresql.conf并更改

连接设置-

listen_addresses = '*'          # what IP address(es) to listen on;

在/etc/postgresql/10/main/pg_hba.conf 中

IPv4本地连接:

host    all             all             0.0.0.0/0           md5

现在重新启动DBMS

sudo service postgresql restart

现在您可以连接

psql -h hostname(IP) -p 5432 -U postgres

最新更新