react native app with nodejs as my backend and postgres as my database

本小妞迷上赌 提交于 2021-02-05 09:23:07

问题


I have successfully connected my nodejs backend and my PostgreSQL database to my ubuntu server. I have also installed nginx as a reverse proxy and it is working when i access the public ip address on the browser.

When i cd to my backend folder that contains my index.js and do sudo node index.js:

i get

Server started on port 9000... Executing (default): SELECT 1+1 AS result Database Connected...

and on my IOS simulator, my posts and everything get loaded correctly.

My problem is when i close my node.js server and install pm2 and configure pm2 correctly when i try to load my IOS simulator an in-app error gets appears and nothing is loaded. (i copied everything from my local database into the ubuntu database, hence the same posts must be shown)

my pm2 logs show this:

[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/home/ubuntu/.pm2/pm2.log last 15 lines:
PM2        | 2021-01-27T06:26:49: PM2 log: PM2 version          : 4.5.1
PM2        | 2021-01-27T06:26:49: PM2 log: Node.js version      : 12.20.1
PM2        | 2021-01-27T06:26:49: PM2 log: Current arch         : x64
PM2        | 2021-01-27T06:26:49: PM2 log: PM2 home             : /home/ubuntu/.pm2
PM2        | 2021-01-27T06:26:49: PM2 log: PM2 PID file         : /home/ubuntu/.pm2/pm2.pid
PM2        | 2021-01-27T06:26:49: PM2 log: RPC socket file      : /home/ubuntu/.pm2/rpc.sock
PM2        | 2021-01-27T06:26:49: PM2 log: BUS socket file      : /home/ubuntu/.pm2/pub.sock
PM2        | 2021-01-27T06:26:49: PM2 log: Application log path : /home/ubuntu/.pm2/logs
PM2        | 2021-01-27T06:26:49: PM2 log: Worker Interval      : 30000
PM2        | 2021-01-27T06:26:49: PM2 log: Process dump file    : /home/ubuntu/.pm2/dump.pm2
PM2        | 2021-01-27T06:26:49: PM2 log: Concurrent actions   : 2
PM2        | 2021-01-27T06:26:49: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-01-27T06:26:49: PM2 log: 
===============================================================================
PM2        | 2021-01-27T06:26:49: PM2 log: App [app:0] starting in -fork mode-
PM2        | 2021-01-27T06:26:49: PM2 log: App [app:0] online

/home/ubuntu/.pm2/logs/app-error.log last 15 lines:
0|app   | WARNING: NODE_APP_INSTANCE value of '0' did not match any instance config file names.
0|app   | WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
0|app   | WARNING: No configurations found in configuration directory:/home/ubuntu/config
0|app   | WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.

/home/ubuntu/.pm2/logs/app-out.log last 15 lines:
0|app   | Server started on port 9000...
0|app   | ErrorSequelizeConnectionError: password authentication failed for user "ubuntu"

回答1:


The thing is P2M caches env variables. Try to update env vars with the following command

pm2 restart {app name} --update-env

Edit PM2 does not load env from .env file. To tackle this task is easier with a pk2 ecosystem config where you can place your env variables.

module.exports = {
  apps : [
      {
        name: "myapp",
        script: "./app.js",
        watch: true,
        env: {
          "NODE_ENV": "development",
        }
      }
  ]
}


来源:https://stackoverflow.com/questions/65915465/react-native-app-with-nodejs-as-my-backend-and-postgres-as-my-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!