evershopcommerce / evershop

🛍️ NodeJS E-commerce Platform
https://evershop.io/
GNU General Public License v3.0
4.49k stars 1.24k forks source link

[BUG] When deploying on AWS I get error Error: connect ECONNREFUSED 127.0.0.1:5432 #669

Open juancarlosv2711 opened 2 days ago

juancarlosv2711 commented 2 days ago

It seems that at the deploymoment, the instance is trying to connect to postgres locally (127.0.0.1) instead of rds set up.

I have followed documentation here

An i have also created the /var/www/html/current/config/default.json path

The file looks something like this

{ "db": { "name": "my_evershop", "user": "evershop", "password": "evershop", "host": "endpoint.rds.amazonaws.com", "port": 5432 }, "env": { "NODE_ENV": "production", // Set environment to 'production' or 'development' as needed "PORT": 3000 // Define the port the application should run on }, "log": { "level": "info", // The logging level (info, debug, error, etc.) "path": "/var/www/html/logs" // Path where logs will be saved }, "api": { "endpoint": "https://api.example.com" // Define any API endpoints the app may interact with } }

This is the error I get after runnning pm2 start npm -- start (bash script)

`/home/ubuntu/.pm2/logs/npm-out.log last 15 lines: 0|npm | address: '127.0.0.1', 0|npm | port: 5432 0|npm | } 0|npm | 0|npm | > start 0|npm | > evershop start 0|npm | 0|npm | Error: connect ECONNREFUSED 127.0.0.1:5432 0|npm | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1549:16) { 0|npm | errno: -111, 0|npm | code: 'ECONNREFUSED', 0|npm | syscall: 'connect', 0|npm | address: '127.0.0.1', 0|npm | port: 5432 0|npm | }

/home/ubuntu/.pm2/logs/npm-error.log last 15 lines: 0|npm | npm ERR! enoent This is related to npm not being able to find a file. 0|npm | npm ERR! enoent 0|npm | 0|npm | npm ERR! A complete log of this run can be found in: 0|npm | npm ERR! /home/ubuntu/.npm/_logs/2024-11-21T00_02_26_682Z-debug-0.log 0|npm | npm ERR! code ENOENT 0|npm | npm ERR! syscall open 0|npm | npm ERR! path /var/www/html/package.json 0|npm | npm ERR! errno -2 0|npm | npm ERR! enoent ENOENT: no such file or directory, open '/var/www/html/package.json' 0|npm | npm ERR! enoent This is related to npm not being able to find a file. 0|npm | npm ERR! enoent 0|npm | 0|npm | npm ERR! A complete log of this run can be found in: 0|npm | npm ERR! /home/ubuntu/.npm/_logs/2024-11-21T00_02_27_205Z-debug-0.log

`

foundanand commented 13 hours ago

The app is attempting to connect to PostgreSQL on 127.0.0.1 (localhost) instead of your RDS instance. This is likely because the database connection details in your default.json configuration file aren't being properly loaded, or the app is hardcoded to connect to localhost

Try this telnet endpoint.rds.amazonaws.com 5432 and tell what response do you get