0

I got the following error when i run the server im new to Node.js i dont know about "Cannot read property 'length' of undefined" and following issues.

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`

1 Answers1

0

Possibility of error is below.

  • room object is undefined, so its become undefined.length. To resolve it make sure room object should not be undefined wherever you have defined that object.
  • Try to use Object.keys(room).length . This would return the length of object
almcd
  • 1,069
  • 2
  • 16
  • 29