title: Asyncronous module function is not working
body: <p>I'm new to node.js and am facing an issue with await/async functions. This are my files:</p>
  
  <p><strong>main.js</strong></p>
  
  <pre><code>var fd = require('fdmodule');
  let r = await fd.matches();
  console.log('r: ' + r);
  </code></pre>
  
  <p><strong>fdmodule.js</strong></p>
  
  <pre><code>const baseUrl = 'https://api.football-data.org/v2/';
  const token = '*********';
  const https = require('https');
  
  exports.matches = async function () { 
      return new Promise(function (resolve, reject) {   
          let x = await callUrl(baseUrl + 'matches');
          console.log('x: ' + x);
          resolve(x);
      });
  };
  
  async function callUrl(url) {
      return new Promise(function (resolve, reject) {
          var req = require('request');
          var header = { headers: { 'X-Auth-Token': token } };
          req(url, header, function (error, response, body) {
              if (!error &amp;&amp; response.statusCode == 200) {
                  resolve(body);
              } else {
                  reject(error);
              }
          });
      });
  }
  </code></pre>
  
  <p>This is my output:</p>
  
  <pre><code>let r = await fd.matches();
          ^^^^^
  
  SyntaxError: await is only valid in async function
  </code></pre>
  
  <p>When I remove the <code>await</code> of this line and change my function to</p>
  
  <pre><code>exports.matches = function () {     
      let x = await callUrl(baseUrl + 'matches');
      console.log('x: ' + x);
      return x;    
  };
  </code></pre>
  
  <p>I get the <code>console.log('x: ' + x);</code> result, but only after the <code>console.log('r: ' + r);</code> which obviously is blank.</p>
  
  <p>What am I doing wrong?</p>