I'm trying to create on a function that makes an axios request to a certain API and returns the data it gets back. I understand it has to be asynchronous, and I'm trying to build the function like that in NodeJS, but it keeps giving me a "promise pending" and doesn't return the data. It will do a console log, but I need to get the data returned whenever I call this function. The code I'm working with:
import axios from 'axios';
export default function simple() {
const url = 'https://api.somerandomfakeurl.com/'
return getData(url)
}
async function getData(url){
const data = await axios(url).then(response => { return response })
return data
}
So when I call on the simple() function, I want to get the response data. Anyone knows what I'm doing wrong? Thanks!