I'm making an HTTP request to an API and would like to save the response body into a MongoDB Collection.
But because node is asynchronous I can't find a way to reference my data outside the callbacks, and Meteor does not allow saving into a collection outside the main fiber.
I've tried event emitters but they are still outside the fiber, also attempted to use Meteor.wrapAsync, but have not been able to structure it right.
Thanks!
var api_data;
function getData(url, callback) {
request(url, callback);
};
function parseData(error, response, body)
{
var localData = JSON.parse(body);
api_data = localData; <-- How to get this outside the callback.
};
getData(api_url_full, parseData);