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

210
Visualizações
how to return async function node.js

I'm trying to take data form a get requet to Airtable and put the records into an array called aTotalRecords. I cannot get this function to return the data. I've tried a bunch of combinations of async/await and .then(). I know this subject has been covered by answers like this one and I've read a couple posts like this. But, I cannot get it to work. What am I missing.

import Airtable from 'airtable';
import oConfig from './configFile.js';

function getAirtableData(){

    var base = new Airtable({apiKey: oConfig.oConfig.airtableAPIKey}).base(oConfig.oConfig.airtableBaseKey);
    var aTotalRecords = []; 
    base('Polygon Transactions').select({
        
        maxRecords: 500
    }).eachPage(function page(records, fetchNextPage) {

        records.forEach(function(record) {
            aTotalRecords.push(record.get('tx_hash'));
        });

        fetchNextPage();

    }, function done(err) {
        if (err) { console.error(err); return; }
    });

    // return Promise
    // console.log(aTotalRecords)
    // return await Promise.resolve(aTotalRecords)
    return aTotalRecords
    
};

// getAirtableData().then(console.log);

async function allAirtableRecords() {
    return getAirtableData();
};

allAirtableRecords().then(console.log);
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