When I start my nodejs app (with dust) on localhost:3000 the following code is used to grab all rows from my products tables (postgres db) and display them on my index page. It seemed to work fine last week.
app.get('/', async (req, res) => {
var parms = req.query.record;
const results = await pool.query('SELECT * FROM products WHERE id = $1',[parms], function (err, result) {
if (err) {
return console.error('error running query', err);
}
res.render('index', { products: result.rows });
});
});
For some reason now "req.query.record" is empty "[ ]" so no results are displayed on my index page.
If I navigate to localhost:3000/?record=3 it works fine and I can see the one record on my index page.
Also, if I edit the "results" in the original code and change [parms]
to [3]
then it works fine as well and displays that one record on my index page.
what would cause var parms = req.query.record;
to return an empty object? Is that the expected behavior?