I am trying to pass a SQLite request stored into a variable to a pug template. My program works fine if using a string value passed to my pug view. But i always get an empty or undefined variable in my html when using the stored request result. I ve been reading many posts and tried multiple explanations but i still cant figure out what is wrong with my code.
Here is my server code
router.get('/mydata', function(req, res){
var sqlite3 = require('sqlite3').verbose();
var mydb = new sqlite3.Database('mydb');
var data = {};
mydb.serialize(function() {
var rowset = mydb.each("SELECT * FROM mytable", function(err, row) {
data[row.id] = {
name: row.name,
};
res.render('mydata', {
data: data
});
});
});
});
here is my pug code
script.
var data = data
Precision : object data is fine when i print it on the server side.
Thanks a lot for any help (and sorry if it s an asynch beginer issue...)