title: getting error 'await is only valid in async functions' from inside an asynchronous function
body: <p>I assume that this is because some other function that is not async is encasing it maybe? i cannot for the life of me work out what it could be though or how to fix it - (i am pretty much totally new to node so i apologise if this is a really basic question but i couldn't find an answer in any previously asked.)</p>
  <p>here is the code:</p>
  <pre><code>http.createServer(async function (req, res) {
      let data = ''
      req.on('data', chunk =&gt; {
          data += chunk;
      });
      req.on('end', () =&gt; {
          try {
              response =  await query();
          } catch (e) {
              response = e;
          }
          res.write(response);
          res.end();
      });
  }).listen(8080);
  </code></pre>
  <p>in which <em>query()</em> is an async function that waits for a response from a bigquery server. the function works fine if placed before the first <em>req.on('data')</em> segment, but not if it is any later in the code than this. Any clues why?</p>
  <p>Thanks in advance.</p>