Apologies as I'm a bit of a beginner, but am trying to put the get request in variable within a function so that I can call it in another function and have it return the JSON.
function getRequest (url, response) {
var response = request.get({
url: url,
json: true,
headers: {'User-Agent': 'request'}
}, (err, res, data) => {
if (err) {
console.log('Error:', err);
} else if (res.statusCode !== 200) {
console.log('Status:', res.statusCode);
} else {
console.log(data);
}
});
}
Then I have
var result = getRequest(urlPlaylist);
and have it return the JSON from the function. Can someone help me figure out how to structure that callback? Thank you!