title: Javascript: Exit script after async function
body: <p>I am trying to create a database setup script for a nodeJS project.
  I have the following async function  <code>createTable</code> that queries a <strong>PostgreSQL</strong> database.</p>
  
  <p>The problem is that the script does not quit after all the operations have been carried out.
  I have tried appending <code>process.exit(0)</code> to the end of the file but that just prematurely kills the script (I think it executes while the async operations are running).</p>
  
  <p>How do I properly exit the script after operations are done? </p>
  
  <pre><code>const dbInit = () =&gt; {
    const createTable = async (creationQuery, tableName) =&gt; {
      try {
        const created = await client.query(creationQuery);
        if (created) logger(`'${tableName}' table created successfully`);
      } catch (err) {
        logger(err.message);
      }
    };
  
    createTable(Schemas.userModel, 'Users');
    createTable(Schemas.orderModel, 'Orders');
  };
  dbInit();
  </code></pre>