'Cannot read property 'length' of undefined' nodeJS
express, node.js, pug, sqlite
Solution
res.render('students', { title: 'list' });
and this line
each item, i in results
The variable names do not match.
From the picture, I can see that you are rendering the page called `students.jade`. For that page, you are sending variable `title` to Jade but you declared that the variable would be called `results` in Jade.
Problem
I'm getting started in Node.js and I'm completely confused as to why I can't get the results of my SQL query to render on a page, i'm using sqlite3. This is a part of my index.js file ``` router.get('/students', function (req, res, module) { var fs = require("fs"); var file = "./test.db"; var exists = fs.existsSync(file); if (!exists) { console.log("Creating DB file."); fs.openSync(file, "w"); } var sqlite3 = require("sqlite3").verbose(); var db = new sqlite3.Database(file); db.serialize(function () { if (!exists) { db.run("Create table students ( ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, Nom varchar (255), Prenom varchar (255) );"); } }); db.all('SELECT * FROM students', function selectCb(err, rows, fields) { if (err) { throw err; } for (var i in rows) { console.log(rows[i]); } res.render('showResults.jade', { results: rows }); }); db.close(); res.render('students', { title: 'list' }); }); ``` This is my Jade (create.jade) file; ``` block content form(method='get', action='/students/create') button(type='submit') Creer ul each item, i in results li #{item.Nom} (#{item.Prenom}) li= JSON.stringify(item) ``` I put all of this things in my express app, I launch it with my shell, I receive all the sql data like this: ``` { ID: 1, Nom: 'zeze', Prenom: 'zeze' } { ID: 2, Nom: 'ertty', Prenom: 'uuuuuuuuuuu' } ``` But my /students page show a message https://i.stack.imgur.com/ormUG.png Could you please help me, I'm really desperate. (Sorry for my bad english I'm French) ^^