Upcoming database upgrades. to improve our reliability at 03:30 UTC on Feb. 25 / 7:30pm PT on Feb. 24. Some users may briefly experience slow load times or error messages. Learn more here

How to store retrieved record as variable in node.js

Topic Labels: API
1504 1
Showing results for 
Search instead for 
Did you mean: 

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; }

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

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)