I followed this little how to to apply a simple api in nodejs. It is not quite my area of expertise, I am a Computer Network Analyst and although I develop applications in C ++ (simple) and C #, I have a small doubt on how to obtain the result of an array returned by the following code:
Javascript Code using Mysql ->
//
exports.findAll = (req, res) => {
const name = req.query.name;
var condition = name ? { name: { [Op.like]: `%${name}%` } } : null;
Custumers.findAll({ where: condition })
.then(data => {
res.send(data);;
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving name."
});
});
};
Access to URL to check if everything goes as expected.
http://10.1.1.254:8085/api/custumers?name=Gabriel
My result:
[
{"id":6,
"name":"Gabriel",
"cod":10,
"igCustumer":"1",
"createdAt":null,
"updatedAt":null}
]
How could I get the values of name, cod, imgCustumer?
Im try;
axios.get(`http://10.1.1.254:8085/api/custumers?name=Gabriel`).then((res) => {
let myvar = `My result:\n\n${res.data.name}`;
console.log(myvar);
})
Result if : Undefinid