very new to JavaScript and API building. I’m writing a simple address verification system and I’m running into an issue where the response sends the buffer data in addition to the response of the columns that I want to query. I know that I should be returning rows and fields, but do not know how to fit it into the code.
This is what I currently have for the main query:
app.get("/addresses/api/find/", async (req, res) => {
try {
const address1 = req.query.Address1;
const address2 = req.query.Address2;
const city = req.query.City;
const state = req.query.State;
const zip = req.query.ZipCode;
console.log(req.body);
const findAddress = await pool.query ("SELECT * FROM addresses WHERE Address1 = ?",
[
address1,
]
);
res.json({
status: "Success: 200",
message: "There was a match to your address.",
findAddress
});
} catch (err) {
console.error(err.message)
}
})
And this is a part of what is returned when there is no exact match:
{
"status": "Success: 200",
"message": "There was a match to your address.",
"findAddress": [
[],
[
{
"_buf": {
"type": "Buffer",
"data": [
1,
0,
0,
1,
6,
47,
0,
0,
2,
3,
100,
I’m still working on the logic to reject an empty set, but I have not gotten that far, yet.
Thank you.
2
Answers
I was actually able to limit the output to only the rows by dropping by variable into brackets and requesting only that information back.
It gave me this response:
try to convert data value to string type ,then you can see results.