I've been trying to build an API integrated section for my website since it needs a news section. I have a small amount currently built but am struggling with getting it to work. This is through using an API from news_api.org as well as Axios.
Here's my code:
app.get('/articles', async (req,res)=>{
try{
const articles = await response;
axios.get('https://newsapi.org/v2/everything')({
params: {
q: 'eco technolgy',
language: 'en',
sortBy: 'relevancy',
api_key: process.env.NEWS_API_KEY
}
});
res.render('news')
} catch{
res.status(500).json({ message: "cant find news", error} );
}
});
I've tried everything I can think of and can find on other forums but I'm now just questioning if I'm doing it wrong.
const articles = await response;
- What isresponse
here? Did you mean toawait
the call toaxios.get()
instead? And then did you mean to do something witharticles
?