node.js - Unable to connect to Postgres on EC2: ECONNREFUSED -


i have node server hosted on ec2 instance trying connect postgres running on same instance. when start server econnrefused error db:

unable connect database: sequelizeconnectionrefusederror: connect econnrefused x.x.x.x:5432

i using sequelize orm package npm:

import sequelize 'sequelize'; const db = new sequelize('postgres://postgres@52.9.136.53/unloadx' {dialect: 'postgres'}); 

postgres running on instance, , have port 5432 open in inbound security rule. can confirm postgres running ps aux | grep postgres shows multiple postgres related processes, , netstat -anp --tcp confirms postgres appears listening on port:

active internet connections (servers , established) proto recv-q send-q local address           foreign address         state       pid/program name tcp6       0      0 ::1:5432                :::*                    listen      - 

but when scan port nmap x.x.x.x -p 5432 shows port status closed. per nmap, means port accessible has no application listening on able respond packets.

appreciate in getting connection work.

one problem using public ip address. means database connection going out internet , back. prevent security group rule working, , introduce security , latency issues.

if trying connect server in vpc want connect using private ip. however, since it's on same instance can delete security group rule , use localhost or 127.0.0.1.


Comments