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

228
Vistas
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
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