module.exports = function(app){
app.get('/produtos',function(req,res){
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'Root1997:28:',
database : 'casadocodigo_nodejs'
});
connection.query('selecy * from livros', function(err,results){
res.render('produtos/lista',{lista:results});
});
connection.end();
});
}igo aqui
e como resposta aparece isso
TypeError: /root/desenvolvimento/curso/app/views/produtos/lista.ejs:10
8| <td>preco</td>
9| </tr>
>> 10| <%for(var i=0;i<lista.length;i++) {%>
11| <tr>
12| <td><%=lista[i].id%></td>
13| <td><%=lista[i].titulo%></td>
Cannot read property 'length' of undefined
at eval (eval at compile (/root/desenvolvimento/curso/node_modules/ejs/lib/ejs.js:618:12), <anonymous>:11:26)
at returnedFn (/root/desenvolvimento/curso/node_modules/ejs/lib/ejs.js:653:17)
at tryHandleCache (/root/desenvolvimento/curso/node_modules/ejs/lib/ejs.js:251:36)
at View.exports.renderFile [as engine] (/root/desenvolvimento/curso/node_modules/ejs/lib/ejs.js:482:10)
at View.render (/root/desenvolvimento/curso/node_modules/express/lib/view.js:135:8)
at tryRender (/root/desenvolvimento/curso/node_modules/express/lib/application.js:640:10)
at EventEmitter.render (/root/desenvolvimento/curso/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/root/desenvolvimento/curso/node_modules/express/lib/response.js:1008:7)
at Query.<anonymous> (/root/desenvolvimento/curso/app/routes/produtos.js:12:10)
at Query.<anonymous> (/root/desenvolvimento/curso/node_modules/mysql/lib/Connection.js:502:10)