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

222
Views
function that checks promise response returns Promise { <pending> } instead of true or false

I have some nodejs code used to retrieve data from google maps API:

const mapsAPI = new Client({});

let countryData = mapsAPI.reverseGeocode( {
    params: {
      latlng: latlng, // there's probably a better way of doing this
      key: process.env.GOOGLE_MAPS_API_KEY,
    },
    timeout: 1000, // in miliseconds
  })
  .then((response) => {
    // console.log(response.data.results[0].reverseGeocode); // prints whole response
    // console.log(response.data.results[7].types); // prints types 'country' and 'political'
    // console.log(response.data.results[7].formatted_address); // prints country
    country = response.data.results[7].formatted_address;
    console.log(country);
    return country;
  })
  .catch((e) => {
    console.log(e.response.data.error_message); // NOTE: this will only return API errors
  });
// i know the code is a mess, will fix later
// maybe could make this a function and just return response data

async function checkAddress() {
  const a = await countryData;
  // console.log(a);
  if (a === 'United States') {
    console.log('true');
    return true;
  }
  else {
    console.log('false');
    return false;
  }
  return false;
}

console.log(checkAddress()); // returns Promise { <pending> } for some reason

checkAddress() should return true or false, but returns Promise { <pending> }, what am I doing wrong?
new to async await, please dont kill me

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!