Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda