title: How to export async function from a node module
body: <p>I'm trying to write a node module, to handle my various db calls.
  I want to use async/await where ever I can, but I'm having some issues with it.</p>
  
  <p>I've been using promises a bit, and export those functions fine.
  Example:</p>
  
  <pre><code>function GetUsernames() {
      return new Promise(function (resolve, reject) {
          sql.connect(config).then(function () {
              new sql.Request()
                  .query("SELECT [UserName] FROM [Users] ORDER BY [LastLogin] ASC").then(function (recordset) {
                      resolve(recordset);
                  }).catch(function (err) {
                      reject(err);
                  });
          });
      });
  }
  </code></pre>
  
  <p>And then I export in the following:</p>
  
  <pre><code>module.exports = {
      GetUsernames: GetUsernames,
      GetScopes: GetScopes,
      UpdateToken: UpdateToken,
      SetOwner: SetOwner
  };
  </code></pre>
  
  <p>But, how should I do this, with an async function, to use the async/await that is available in node7?</p>
  
  <p>Do I still just return a promise? I tried doing that, but when I then call it in my code, it doesn't work.</p>
  
  <pre><code>const db = require("dataprovider");
  ...
  var result = await db.GetUsernames();
  </code></pre>
  
  <p>It gives me: </p>
  
  <blockquote>
    <p>SyntaxError: Unexpected identifier</p>
  </blockquote>
  
  <p>on the db name (works fine if I just use the promise functions, with then().)</p>
  
  <p>Maybe my google skills are terrible, but I haven't managed to google anything I could use, on this issue. </p>
  
  <p>How on earth do I make an async function, in my module, that I can await elsewhere?</p>