I am trying to make an API call using NodeJS. Unfortunately, I am not sure how to grab the object from inside the JS function so I can parse for attributes and store as a variable in the main function. I understand that I am calling a function within a function (inline asyncronous) How would I grab the myData object from this functionn?
var request = require('request')
function getData(URL){
var url = URL;
request('http://api.smmry.com?SM_API_KEY=APIKEYHERE&SM_URL=' + URL, function (error, response, body) {
var myData = new Object();
myData = JSON.parse(body); //We need to turn this into an object in order to grab its attributes.
return myData;
});
}
console.log(getData('http://www.cnn.com/2017/07/16/politics/mark-warner-jay-sekulow-donald-trump-jr/index.html'))
Thank you.