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

104
Vistas
How to return response to front end from post request in node?

I'm trying to make a POST request from node after a POST request from the client and pass the backend response back to the client. How can I pass the post response from the backend back to the post request originally from the frontend? I can access the promise in the async scope but how can I... err... push it/fart it back out to the client end? Thankyou.

async function sendToken() {
            return await axios
                .post("http://localhost:3001/Recaptcha", {token: token})
                .then((res) => {
                    console.log('client recaptcha sent');
                    return res;
                })
                .catch((err) => console.log(err, 'recaptcha not sent'));
        }
app.post('/Recaptcha', (req, res) => {

  let p = new Promise((resolve, reject) => { // just to see if it would work
  console.log(req.body.token)
  const token = req.body.token
  const secret = process.env.secret

  async function validateRecaptcha() {
    return await axios
      .post(`https://www.google.com/recaptcha/api/siteverify?secret=${secret}&response=${token}`)
      .then((res) => {
        console.log('server recaptcha sent');
        resolve(res);
        return res;
      })
      .catch((err) => console.log(err, 'recaptcha not sent'));
  }
  
  validateRecaptcha().then((res) => {
    console.log("recaptcha data:", res.data);
    //if (res.data.success === true) { // *if I could do this everything would work*
    //  res.send("HELLO")
    //}
    p.then((result) => { // I can access a promise result, but how do I push it... up?
      console.log("p:", result.data)
      res.send(result.data) // res.send is not a function error
    })
  })

  console.log(validateRecaptcha.res) // undefined, pending promise
  if (res.data.success === true) { // *how do I access this data to send to front?*
    res.send("HELLO")
  } 
})

});
about 4 years ago · Juan Pablo Isaza
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