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

169
Visualizações
Use returned object outside of an async function

I have the following function that gets a survey from Qualtrics:

const fetchQualtricsSurvey = async () => {
    const token = await getAccessToken();
    const progress = await startResponseExport(token);
    const fileId = await getResponseExportProgress(token, progress);
    const survey = await getResponseExportFile(token, fileId);
    console.log(survey);
};

fetchQualtricsSurvey();

It's currently logging the survey to the console. However, I want to use the JSON that I get in other parts (e.g., visualizing the data using other libraries).

Everytime I try to create a global variable that holds survey I get a promise pending.

Here is the getResponseExportFile function for reference:

async function getResponseExportFile(accessToken, fileId) {
    try {
        const res = await axios(
            `${baseUrl}/API/v3/surveys/${surveyId}/export-responses/${fileId}/file`,
            {
                headers: {
                    Authorization: `Bearer ${accessToken}`
                }
            }
        );
        return res.data.responses;
    } catch (err) {
        console.log(err);
    }
}

How on earth do I use survey outside of this whole async function? Is it even possible? I need to access properties of survey object and use them as values somewhere else.

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