title: The correct way to invoke an async function main?
body: <p>I have some nodejs scripts - i.e. processes which do a job and complete, rather than run continuously.</p>
  
  <p>I use async functions, for example:</p>
  
  <pre><code>const mysql = require('mysql2/promise');
  ...
  
  async function main() {
      var conn = await mysql.createConnection(config.mysql);
      ...
      var [response, error] = await conn.execute(`
          DELETE something
          FROM some_table
          WHERE field = ?
      `, [value]);
      ...
  </code></pre>
  
  <p>Is the following code: </p>
  
  <pre><code>main().then(() =&gt; process.exit(0)).catch(err =&gt; { console.error(err); process.exit(1); });
  </code></pre>
  
  <p>the best/correct way to start execution of the async code?</p>
  
  <p>(It works, but I want to make sure that I'm not leaving any holes which might cause surprises, such as exceptions being silently swallowed.)</p>
  
  <p>Why does <code>conn.execute()</code> <strong>return</strong> an <code>error</code> (which I need to manually check) rather than throwing one?</p>