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

101
Views
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
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!