I have been able to connect to my sqlite3 database with node.js, I want to use the information from the records in a separate ejs file (index.ejs). Does anyone know if this is possible?
code:
//register sqlite3
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('./db/burger.db');
let sql = 'SELECT id, name from burger WHERE id = ?';
let id = 5;
//first row only
db.get(sql, [id], (err, row) => {
if (err) {
console.log("Error in connecting to first row of db");
}
return row
? console.log(row.id, row.name)
:console.log('No record found with the id ${id}');
});
//listen for requests
app.listen(3001);
app.use(express.static('views'));
app.get('/', (req, res) => {
res.render('index');
});
//404
app.use((req, res) => {
res.status(404).render('404', { title: '404'});
db.close();
});
I'm totally unsure of what steps I have to take to accomplish this. Above is what is found on my app.js, this the node. In a separate folder, "views", my index.ejs file is kept.