title: Nested Async/Await Nodejs
body: <p>Cannot seem to figure out why this is not working for me. I have a parent function that performs an AWAIT on a child load process... the LOAD process in turn calls another AWAIT called LOADDATA... so basically like this:</p>
  
  <pre><code>module.exports = async function () {
      try {
         await load();
  
      } catch (ex) {
          console.log(ex);
          logger.error(ex);
      }
  };
  
  async function load() {
      return await new Promise((resolve, reject) =&gt; {
          TableImport.findAll().then((tables) =&gt; {
             for (let table of tables) {
                  await loadData(table.fileName, table.tableName);
              }
              resolve();
          }).catch(function (err) {
              reject(err);
          })
      })
  };
  
  
  async function loadData(location, tableName) {
      return await new Promise(function (resolve, reject) {
          var currentFile = path.resolve(__dirname + '/../fdb/' + location);
  
          sequelize.query("LOAD DATA LOCAL INFILE '" + currentFile.replace('/', '//').replace(/\\/g, '\\\\') + "' INTO TABLE " + tableName + " FIELDS TERMINATED BY '|'").then(function () {
              resolve(tableName);
          }).catch(function (ex) {
              reject();
          });
      });
  };
  </code></pre>
  
  <p>the AWAIT in the LOAD fails stating:</p>
  
  <p>await loadData(table.fileName, table.tableName);
  SyntaxError: Unexpected identifier</p>
  
  <p>Clearly do not understand something about scope of the async!</p>