1
I’m studying a little bit about nodejs and am facing difficulties to capture and access json Sponse, For example: My Getbyid
exports.getProduto = function(req, res) {
const produtoId = req.params.id
const queryString = "SELECT * FROM produto WHERE idproduto = ?;"
pool.query(queryString, [produtoId], (err, rows, fields) => {
if (err) {
console.log('Erro: ' + err)
res.sendStatus(500)
res.end()
return
}
console.log('SUCESSO!')
res.json(rows)
})
}
When I give the get I have this answer. However I would like to access the json data(fields) and I don’t know how I do it.
[
{
"idproduto": 1,
"nome": "LANCHE",
"preco": 20,
"imagem": null
}
]
How to store the fields individually?
– Felipe Avelar
Try to rephrase the question, maybe something in the sense of json return from a database answer, your question is misspelled.
– André Martins
I just changed.
– user167737