I am trying to grab json data from a pastebin link and serve it as a popup in my electron app, but when trying to return a axios request data, it comes up undefined, also the console.log gets executed earlier than the .then for some reason, I think this has something to do with the request being async, but I haven't found a way to wait for the .then.
Code:
function grabPopup(fetchurl) {
axios
.get(fetchurl)
.then(response => {
// handle success
//console.log(response.data);
return response.data;
})
.catch(function(error) {
// handle error
console.log(error);
});
}
console.log(grabPopup("https://pastebin.com/raw/0L1erTs1"));
The console output:
undefined
{ title: 'Test', message: 'Test2' }