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

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