I am writing an app to track crypto prices to get some work on some of the new coding practices I have been learning. I have ran into a problem where in one of my functions I console.log() a variable and get the answer I need, but when I return that to be set to another variable to use I get a different answer.
I am looking to use an API to scrape prices and other info for crypto and then pass it into a node route to use on the page through ejs. Here is where I am having trouble;
async function axiosTest() {
const response = await axios.get(
'https://api.coingecko.com/api/v3/coins/markets?vs_currency=USD&ids=bitcoin&order=market_cap_desc&per_page=100&page=1&sparkline=false&price_change_percentage=24hr%2C7d'
);
return response.data;
}
const BTCdata = axiosTest().then((data) => {
console.log('in axios test', data[0]);
return data[0];
});
app.get('/', (req, res) => {
console.log('in /GET', BTCdata);
res.render('home');
});
I'm looking to get this data from the API so I can pass it through to my home page template and render the information on my page.
THANK YOU ALL for always being so helpful.