A simplified version of my problem:
var request = require('request');
var myJSONObject;
request.get(largeEndpointThatOnlyHasIDs, {authstuff}, function (err, response, body) {
if (!err && response.statusCode = 200) {
JSON.parse(body).forEach(function(item) {
getItemData(item.item_id, function(result) {
myJSONObject['itemData'] = result;
});
});
}
});
getItemData(id, callback) {
request(itemAPIEndpoint, function(err, response, body) {
if (!err && response.statusCode = 200) {
callback(JSON.parse(body));
}
});
}
Alright, so that kind of works. I can console.log(myJSONObject) inside the callback just fine and see that it's populating it one at a time. Basically I just can't figure out how to wait until the entire forEach has finished, myJSONObject is populated and I can use it for other things.
Sorry, I'm not really sure if I'm explaining what I mean very well. If not, let me know and I will try to clarify a bit more.