How to store retrieved record as variable in node.js


#1

Apologies in advance, this is probably a dumb question but I’m relatively new to airtable and I’m trying to retrieve individual records using the API through node.js and I can’t figure out how to store the JSON output as a variable I can parse through.

From my API documentation, I am being told I can retrieve an individual record using:

base('base-name').find('record-name', function(err, record) {
    if (err) { console.error(err); return; }
    console.log(record);
});

This works perfectly well to print the record to the console. But how do I assign the output to a variable which I can parse through? I’m sorry if this is a dumb question. Really appreciate any help!


#2

You are using an anonymous function to handle the “find” function’s callback so the scope of that variable is going to be within the anonymous function itself.

Coming to your question the output is already assigned to a variable “record”.

In your example you are passing the variable (in this case “record” to the console.log function)