skip to Main Content

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


  1. Chosen as BEST ANSWER

    I was actually able to limit the output to only the rows by dropping by variable into brackets and requesting only that information back.

    console.log(req.body, "Get request reached.");
    const [address] = await pool.query ("SELECT * FROM addresses WHERE (Address1, City, State, ZipCode) = (?, ?, ?, ?)",
      [
        address1,
        city,
        state,
        zip
      ],
    );
    

    It gave me this response:

    {
      "status": "Success: 200",
      "message": "There was a match to your address.",
      "address": [
        {
          "id": 112,
          "Address1": "16 Blue Sage Circle",
          "Address2": "",
          "City": "Atlanta",
          "State": "GA",
          "ZipCode": "30318-1030"
        }
      ]
    }
    

  2. try to convert data value to string type ,then you can see results.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search