express js, mysql query backend, get request

14 views Asked by At

I'm using insomnia to send get request to my backend but there's no error and data even there are data's in it, just a empty bracket []

router.get("/", getAnswers);

export const getAnswers = (req, res) => {
  const q =
    "SELECT a.*, u.id AS user_id, username, image FROM answers AS a JOIN users AS u ON (u.id = a.user_id) WHERE a.question_id = ? ORDER BY a.created_date DESC";

  db.query(q, [req.query.question_id], (err, data) => {
    if (err) return res.status(500).json(err);
    return res.status(200).json(data);
  });
};

**i want to get data's like **

[
 {
  "id": 1,
  "desc": "test",
  "user_id":"1"
 },
 {
  etc...
 }
]

just like that.

0

There are 0 answers