使用 nodejs 作为我的后端和 postgres 作为我的数据库来响应本机应用程序 [英] react native app with nodejs as my backend and postgres as my database

查看:136
本文介绍了使用 nodejs 作为我的后端和 postgres 作为我的数据库来响应本机应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功将我的 nodejs 后端和我的 PostgreSQL 数据库连接到我的 ubuntu 服务器.我还安装了 nginx 作为反向代理,当我在浏览器上访问公共 IP 地址时它可以工作.

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.

当我 cd 到包含我的 index.js 的后端文件夹并执行 sudo node index.js 时:

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

我明白

服务器在 9000 端口启动...正在执行(默认):SELECT 1+1 AS result Database Connected...

在我的 IOS 模拟器上,我的帖子和所有内容都能正确加载.

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

我的问题是,当我关闭我的 node.js 服务器并安装 pm2 并正确配置 pm2 时,当我尝试加载我的 IOS 模拟器时,出现应用内错误,但没有加载任何内容.(我将本地数据库中的所有内容复制到 ubuntu 数据库中,因此必须显示相同的帖子)

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)

我的 pm2 日志显示:

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"

推荐答案

P2M 缓存环境变量.尝试使用以下命令更新环境变量

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

pm2 restart {app name} --update-env

编辑PM2 不会从 .env 文件加载 env.使用 pk2 生态系统配置可以更轻松地完成此任务,您可以在其中放置环境变量.

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",
        }
      }
  ]
}

这篇关于使用 nodejs 作为我的后端和 postgres 作为我的数据库来响应本机应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆