Não sei o que esta acontecendo, poderiam me ajudar?
TypeError: /home/emerson/Documentos/NodeJs/casadocodigo/app/views/produtos/lista.ejs:11
9| </tr>
10| <tr>
>> 11| <%for(var i=0;i<lista.length;i++){%>
12| <tr>
13| <td><%=lista[i].id%></td>
14| <td><%=lista[i].titulo%></td>
Cannot read property 'length' of undefined
at eval (eval at compile (/home/emerson/Documentos/NodeJs/node_modules/ejs/lib/ejs.js:549:12), <anonymous>:11:27)
at returnedFn (/home/emerson/Documentos/NodeJs/node_modules/ejs/lib/ejs.js:580:17)
at tryHandleCache (/home/emerson/Documentos/NodeJs/node_modules/ejs/lib/ejs.js:223:34)
at View.exports.renderFile [as engine] (/home/emerson/Documentos/NodeJs/node_modules/ejs/lib/ejs.js:437:10)
at View.render (/home/emerson/Documentos/NodeJs/casadocodigo/node_modules/express/lib/view.js:135:8)
at tryRender (/home/emerson/Documentos/NodeJs/casadocodigo/node_modules/express/lib/application.js:640:10)
at Function.render (/home/emerson/Documentos/NodeJs/casadocodigo/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/home/emerson/Documentos/NodeJs/casadocodigo/node_modules/express/lib/response.js:1008:7)
at Query._callback (/home/emerson/Documentos/NodeJs/casadocodigo/app/routes/produto.js:12:17)
at Query.Sequence.end (/home/emerson/Documentos/NodeJs/casadocodigo/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
module.exports = function (app) {
app.get('/produtos', function (req, res) {
var mysql = require('mysql');
var connection = mysql.createConnection({
host:"localhost",
user:"root",
password:"",
database:"casadocodigo",
});
connection.query('select * from produtos',function(err,result){
res.render('produtos/lista',{lista:result});
});
connection.end();
});
}
<body>
<table>
<tr>
<td>id</td>
<td>titulo</td>
<td>descricao</td>
<td>preco</td>
</tr>
<tr>
<%for(var i=0;i<lista.length;i++){%>
<tr>
<td><%=lista[i].id%></td>
<td><%=lista[i].titulo%></td>
<td><%=lista[i].descricao%></td>
<td><%=lista[i].preco%></td>
</tr>
<%}%>
</tr>
</table>
</body>
</html>