使用本地主机节点项目访问服务器上的数据库

I have bought a VPS for my website. I have built a small project with vue and node. In this I used postgresql that is working fine on localhost. I want to change my database from localhost to the server database where I have installed postgres and made a database and table. My db.js file looks like this: 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; Then I tried to send form data from the localhost vue page and it gave the following error: 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 I do not have much knowledge about this and how to solve this. Can you please guide me what should I do to connect with my server db?


I follow these steps and it worked: edit your /etc/postgresql/9.1/main/postgresql.conf and change Connection Settings - listen_addresses = '*' # what IP address(es) to listen on; In /etc/postgresql/10/main/pg_hba.conf IPv4 local connections: host all all 0.0.0.0/0 md5 Now restart your DBMS sudo service postgresql restart Now you can connect with psql -h hostname(IP) -p 5432 -U postgres