Nodejs服务器移至云后无法响应

问题描述 投票:0回答:1

我刚刚将nodejs 10.16.3服务器移至云中,以使用React native 0.61应用程序和postgres 11进行测试。 android模拟器曾经与运行在同一台PC上的Nodejs服务器和postgres 11服务器一起使用。但是模拟器移到云端后会抛出Network failed错误:

10-03 12:07:48.495 17334 17384 I ReactNativeJS: 'Signup post URL : ', 'http://myip:3000/api/users/signup'
10-03 12:07:48.513 17334 17384 I ReactNativeJS: 'obj : ', '{"_device_id":"ce0e244d684db","cell":"1234563200","cell_country_code":"1","name":"jccc","corp_name":"i am here"}'
10-03 12:09:03.370 17334 17384 I ReactNativeJS: 'error signing up: ', { [TypeError: Network request failed]  //<<<==== ERROR on RN app
10-03 12:09:03.370 17334 17384 I ReactNativeJS:   line: 26749,
10-03 12:09:03.370 17334 17384 I ReactNativeJS:   column: 31,
10-03 12:09:03.370 17334 17384 I ReactNativeJS:   sourceURL: 'http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false' }

nodejs服务器成功以pm2 start index.js启动,并且pm2 logs弹出以下日志:

ubuntu@ip-12-30-0-93:~$ pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/home/ubuntu/.pm2/pm2.log last 15 lines:
PM2        | 2019-10-01T04:52:29: PM2 log: Time                 : Tue Oct 01 2019 04:52:29 GMT+0000 (Coordinated Universal Time)
PM2        | 2019-10-01T04:52:29: PM2 log: PM2 version          : 3.5.1
PM2        | 2019-10-01T04:52:29: PM2 log: Node.js version      : 10.16.3
PM2        | 2019-10-01T04:52:29: PM2 log: Current arch         : x64
PM2        | 2019-10-01T04:52:29: PM2 log: PM2 home             : /home/ubuntu/.pm2
PM2        | 2019-10-01T04:52:29: PM2 log: PM2 PID file         : /home/ubuntu/.pm2/pm2.pid
PM2        | 2019-10-01T04:52:29: PM2 log: RPC socket file      : /home/ubuntu/.pm2/rpc.sock
PM2        | 2019-10-01T04:52:29: PM2 log: BUS socket file      : /home/ubuntu/.pm2/pub.sock
PM2        | 2019-10-01T04:52:29: PM2 log: Application log path : /home/ubuntu/.pm2/logs
PM2        | 2019-10-01T04:52:29: PM2 log: Process dump file    : /home/ubuntu/.pm2/dump.pm2
PM2        | 2019-10-01T04:52:29: PM2 log: Concurrent actions   : 2
PM2        | 2019-10-01T04:52:29: PM2 log: SIGTERM timeout      : 1600
PM2        | 2019-10-01T04:52:29: PM2 log: ===============================================================================
PM2        | 2019-10-01T04:53:40: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2019-10-01T04:53:40: PM2 log: App [index:0] online

/home/ubuntu/.pm2/logs/index-out.log last 15 lines:
0|index    | undefined
0|index    | env var: undefined
0|index    | Listening on port undefined...

/home/ubuntu/.pm2/logs/index-error.log last 15 lines:
0|index    |    { Error: connect ECONNREFUSED 127.0.0.1:5433
0|index    |        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
0|index    |      errno: 'ECONNREFUSED',
0|index    |      code: 'ECONNREFUSED',
0|index    |      syscall: 'connect',
0|index    |      address: '127.0.0.1',
0|index    |      port: 5433 },
0|index    |   original:
0|index    |    { Error: connect ECONNREFUSED 127.0.0.1:5433
0|index    |        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
0|index    |      errno: 'ECONNREFUSED',
0|index    |      code: 'ECONNREFUSED',
0|index    |      syscall: 'connect',
0|index    |      address: '127.0.0.1',
0|index    |      port: 5433 } }

日志消息对我来说似乎很模糊,我不知道问题出在哪里。在云中控制台日志和调试Nodejs服务器的更好方法是什么(与console.log输出类似)?

这里是Nodejs服务器应用程序中的db.js

const express = require("express");
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
const Sql = require("sequelize");
const db = new Sql('emps', 'postgres', `${process.env.DB_PASSWORD}`, {
    host: 'localhost',
    dialect: 'postgres',
    port:5433,
    //operatorsAliases: false
} );

db
    .authenticate()
    .then(() => {
        console.log('DB connection has been established successfully.');
        // The event will be called when a client is connected.

    })
    .catch(err => {
        console.error('Unable to connect to the database:', err);
    });

module.exports = db;
node.js postgresql react-native
1个回答
0
投票
您的端口是undefined。您的.env文件似乎有问题。

... 0|index | env var: undefined 0|index | Listening on port undefined...

© www.soinside.com 2019 - 2024. All rights reserved.