So, looking at the documents with promises, promises, that's what I
function get_data_id(searchValue) { rp('http://example.com?data=searchValue') .then(function(response) { return JSON.parse(response).id; }); }
And then I use this code elsewhere in the script
console.log(get_data_id(searchValue));
However, it returns undefined .
If I change return JSON.parse(response).id to console.log(JSON.parse(response).id) , I get the following
undefined valueofID
So, the value I'm trying to return is definitely correct / correct, but I cannot figure out how to return it as a value.
source share