Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
React axios JSON.stringify() use to [Object object] -> "[Object object]"

i'm junior fronted developer, and i want to your help...

below my pages code

  const sendAnotherIp = async () => {
    const domain_format = /^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?/;

    if (domain_format.test(anotherIp)) {
      await axios
        .get(`${process.env.NEXT_PUBLIC_CLIENT_URL}/api/dnslookup`, {
          params: {
            search: anotherIp,
            date: nowTime,
          },
        })
        .then((res) => {
          alert(res.data);
        });
    } else {
      alert("it's wrong domain format");
    }
  };

  console.log(JSON.stringify(data)); -> "[Object object]"

below my api code

import { NextApiRequest, NextApiResponse } from "next";
const sqlite3 = require("sqlite3").verbose();
const dns = require("dns");

interface Iquerys {
  search: string;
  date: string;
}

interface IUrl {
  ip: string;
}

const dnslookup = (request: NextApiRequest, response) => {
  const req = response.req;

  const querys: Iquerys = req.query;

  const searchData = querys.search;
  const dateData = querys.date;


// below my logic
  response.status(200).end(
    `${dns.resolveAny(searchData, function (err: any, addresses: any) {
      return addresses;
    })}`
  );
//

  // db connect
  let db = new sqlite3.Database("./db/my_database.db", (err) => {
    if (err) {
      return console.log(err.message);
    }
    console.log("Connected to database!");
  });

  // db peristalsis
  db.run("INSERT INTO DnsLookup(search, date) VALUES (?, ?)", [searchData, dateData], (err) => {
    if (err) {
      return console.log(err.message);
    }
    console.log("Row was added to the table: ${this.lastID}");
  });
};

export default dnslookup;

my project build in react, next js. I used to JSON.parse() and JSON.stringify() and toString() ... etc but I can't find a way to real data. what's wrong with my code? help me please guys

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think the server code is the problem. You should wait for the call back to complete then you should send the response.

response.status(200).end(
    `${dns.resolveAny(searchData, function (err: any, addresses: any) {
      return addresses;
    })}`
  );

On the front end code, you should remove await in front of Axios that is not needed.

about 4 years ago · Juan Pablo Isaza Report

0

First declare the headers to be Application/Json

axios.get('m', { headers: { 'Content-Type': 'application/json' } })

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!