title: Do Axios request with SQL array
body: <p>I'm trying to query mySQL database inside Express route, get an array called &quot;subjects&quot;, then run axios request with the array. Then I want to display the responses on EJS.</p>
  <p>Such as,</p>
  <pre class="lang-js prettyprint-override"><code>// for-each &quot;subject&quot;, 
      var url = `http://news.com/${subject}`
      const articles_get =await axios.get(url)
      res.render('news',{articles:articles_get.data.articles})
  </code></pre>
  <p>I tried so many things, I keep getting errors about &quot;async/await must be at the top level&quot; and &quot;HEADERS ALREADY SENT&quot;. I tried following other examples on SO but none have worked. I think I'm missing some idea. Please any help is appreciated!</p>
  <p>Here's my current code that says &quot;SyntaxError: await is only valid in async functions and the top level bodies of modules&quot;
  I tried to move the function out of the route, then call it inside the route, but it just never returned anything.</p>
  <pre class="lang-js prettyprint-override"><code>app.get(&quot;/mySubjects&quot;, (req, res) =&gt; {
    var subjects = [];
    var username = req.body[&quot;username&quot;];
  
    connection.query(
      &quot;SELECT * FROM mySubjects WHERE username = ?&quot;,
      [username],
      async function (error, results, fields) {
        if (error) {
          throw error;
        }
        if (results.length &gt; 0) {
          results.forEach((result) =&gt; {
            subjects.push(result.subject);
          });
  
          subjects.forEach((subject) =&gt; {
            //call NEWS API FOR EACH SUBJECT
            try {
              var url = `https://newsapi.org/v2/top-headlines/sources?category=${subject}apiKey=c7777777777777`;
  
              const news_get = await axios.get(url);
              res.render(&quot;news&quot;, { articles: news_get.data.articles });
            } catch (error) {
              if (error.response) {
                console.log(error);
              }
            }
          });
        } else {
          res.status(401).send({ message: &quot;Nothing is here.&quot; });
        }
      }
    );
  });
  </code></pre>