Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda