I am trying to write an application with Node.js & PostgreSQL, currently I faced a problem in get by id, below is my code
app.get('/monsters/:id', (request, response, next) => {
const { id } = req.params;
pool.query('select * from monsters where id = $1', [id], (err, res) => {
if (err) {
return next(err);
}else {
response.json(res.rows);
}
});
});
it supposed to get the id I typed and return the value I stored in database with a table name called monster, however it just kept returning a blank object {}, I found the problem may because of the $1 part since my atom seemed not able to recognize $, what can I do to fix this problem or is there other way to write this instruction? Thank you!