**Using Node.js to query an Airtable table, I’m extracting records and saving them for later use. How can I apply promises instead of deeply nested callbacks?
Below is an updated sample:
const AirConnect = require('airtable');
AirConnect.configure({
endpointUrl: 'https://api.airtable.com',
apiKey: 'exampleKey12345'
});
const tableBase = AirConnect.base('exampleBaseId');
async function fetchRecords() {
try {
const records = await tableBase('ExampleTable').select({ view: 'Active' }).firstPage();
const results = records.map(rec => ({ title: rec.get('Title'), description: rec.get('Description') }));
console.log(results);
return results;
} catch (err) {
console.error(err);
}
}
fetchRecords();
Thank you and happy coding!