gpt4 book ai didi

javascript - 运行 Node.js 服务器时出现问题

转载 作者:行者123 更新时间:2023-11-29 21:44:23 27 4
gpt4 key购买 nike

当我刚接触 Node.js 时,运行服务器时出现以下错误我不知道“无法读取未定义的属性‘长度’”和以下问题。

MySQL Failure.
{ [Error: connect ETIMEDOUT 211.189.127.226:3306]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '211.189.127.226',
port: 3306,
fatal: true }
TypeError: /home/ubuntu/workspace/Node.JS Server/Streaming/views/page/index.ejs:62
60| <div id="tabs-1">
61| <table class="broadcast_list_table">
>> 62| <%
63| for(var i=0; i<=(room.length/5); i++) {
64| %>
65| <tr>

Cannot read property 'length' of undefined
at eval (eval at <anonymous> (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/ejs/lib/ejs.js:236:14), <anonymous>:48:50)
at eval (eval at <anonymous> (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/ejs/lib/ejs.js:236:14), <anonymous>:87:73)
at exports.compile (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/ejs/lib/ejs.js:249:15)
at Object.exports.render (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/ejs/lib/ejs.js:287:13)
at View.exports.renderFile [as engine] (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/ejs/lib/ejs.js:317:20)
at View.render (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/express/lib/view.js:76:8)
at Function.app.render (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/express/lib/application.js:505:10)
at ServerResponse.res.render (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/express/lib/response.js:756:7)
at Query._callback (/home/ubuntu/workspace/Node.JS Server/Streaming/routes/index.js:42:17)
at Query.Sequence.end (/home/ubuntu/workspace/Node.JS Server/Streaming/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
GET / 500 127413ms
GET / 500 125181ms`

最佳答案

出现错误的可能性如下。

  • 房间对象未定义,因此它变为undefined.length。要解决此问题,请确保在定义房间对象的任何地方都不应未定义该对象。
  • 尝试使用 Object.keys(room).length 。这将返回对象的长度

关于javascript - 运行 Node.js 服务器时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34221192/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com