首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nodejs服务器上云后响应失败

Nodejs服务器上云后响应失败
EN

Stack Overflow用户
提问于 2019-10-04 04:03:26
回答 1查看 71关注 0票数 0

我刚刚将NodeJS10.16.3服务器迁移到云端,以便使用React原生0.61应用程序和postgres 11进行测试。android模拟器用于在同一台PC上运行Nodejs服务器和postgres 11服务器。但是模拟器在迁移到云端后抛出Network failed错误:

代码语言:javascript
复制
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' }

pm2 start index.js启动nodejs服务器成功,pm2 logs调出日志如下:

代码语言:javascript
复制
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

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-04 04:09:02

您的端口是undefined。您的.env文件似乎有一些问题。

代码语言:javascript
复制
...
0|index    | env var: undefined
0|index    | Listening on port undefined...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58226158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档