-4

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.

New contributor
DPDDExamUser-16 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • 1
    const articles = await response; - What is response here? Did you mean to await the call to axios.get() instead? And then did you mean to do something with articles?
    – David
    Commented Apr 22 at 12:22
  • Also, l I hope that's not a real API key? Commented Apr 22 at 12:32
  • 2
    @Thomas please don't drastically alter code like this. Your edit for the API key is OK but changing the latter code does not clarify the question. You might have removed the problem in the code. Or introduced a brand new one. If OP simplified their code and ended up with something illogical, changing the code is at best an attempt to guess what the real error is. But if OP presented their code as-is, then changing it definitely changes what the question is about.
    – VLAZ
    Commented 2 days ago
  • 1
    You've forgotten to tell us what the specific problem is. "Struggling" isn't an error message or a description of unexpected behaviour. We can't diagnose anything based on that. See also How to Ask and remember we can't see your screen.
    – ADyson
    Commented 2 days ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.