I have a problem in node. I'm using sqlite3, which has some seed data in it.
I have this, which runs correctly from the terminal, and outputs a result from the database:
Code:
const db = require('./conn');
function select_user (callback) {
let q = `select uid, uname, pwd from usr`;
db.all(q, function (err, rows) {
if (err) {
console.log('select error = ' + err)
callback(err);
}
callback(rows);
});
}
// select_user((d) => {console.log(d)});
module.exports = { select_user };
If I call from a route, like so:
Code:
var crud = require('../models/crud');
router.get('/', function(req, res, next) {
crud.select_user((d) => { res.render('index.ejs', { title: JSON.stringify(d)})});
})
I only get back an empty array: [].
I've been searching like crazy for an answer, and I don't see what I'm doing different than everything else I'm finding. I've tried many variations on this and nothing works.
What am I missing here...?