Help

How to store retrieved record as variable in node.js

Topic Labels: API
2220 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Lawrence_Humble
4 - Data Explorer
4 - Data Explorer

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!

1 Reply 1
Andrew_Johnson1
8 - Airtable Astronomer
8 - Airtable Astronomer

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)