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

173
Views
Array's of promises pending not sure how to handle

I have tried the usual Promise.all but I get a circular Json error. I have the following promises in my console

all [ Promise { <pending> }, Promise { <pending> } ]
all [ Promise { <pending> } ]
all [ Promise { <pending> } ]
all [ Promise { <pending> } ]

With the following code

const needle = require("needle");

const token = process.env.BEARER_TOKEN_TWITTER;

const endpointUrl = "https://api.twitter.com/2/tweets/search/recent";

export default async function login(req, res) {
  try {
    

    const all = req.body.map((item) => {
      const params = {
        query: `"$${item.title}" from:${item.twitter}`,
      };

      return needle("get", endpointUrl, params, {
        headers: {
          "User-Agent": "v2FullArchiveJS",
          authorization: `Bearer ${token}`,
        },
      }).catch((err) => {
        console.warn(err);
      });
    });


    console.log("all", all);
    // Update
    console.log("allll", await Promise.all(all));


    const result = await Promise.all(all);

    res.status(200).json({ authenticated: true, result: result });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
}

I have read the following with no luck

How to do promise.all for array of array of promises?

Front End Call

const fetchData = async () => {
      const response = newArray.map(
        async (question) => {
          console.log("question", question.data);
          return await fetchTweets(question.data);
        }
      );

      console.log("response", response);


      
      const promise4all = await Promise.all(
        response
        );
        console.log("promise4all", promise4all);
      // setTweets(await Promise.all(response));
    };

enter image description here

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

0

Had to do the following

const needle = require("needle");

const token = process.env.BEARER_TOKEN_TWITTER;

const endpointUrl = "https://api.twitter.com/2/tweets/search/recent";

export default async function login(req, res) {
  try {
    const all = req.body.map((item) => {
      const params = {
        query: `"$${item.title}" from:${item.twitter}`,
      };

      return needle("get", endpointUrl, params, {
        headers: {
          "User-Agent": "v2FullArchiveJS",
          authorization: `Bearer ${token}`,
        },
      }).then(function (response) {
        return response.body;
      });
    });


    const result = Promise.all(all);


    res.status(200).json({ authenticated: true, result: await result });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
}

front end

useEffect(() => {
    // declare the async data fetching function
    const fetchData = async () => {
      const response = newArray.map(
        async (question) => {
          console.log("question", question.data);
          return await fetchTweets(question.data);
        }
      );

      setTweets(await Promise.all(response));
    };

    if (data) {
      fetchData();
    }

  }, [data]);
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!