title: Node Express - Database is created too late causing error
body: <p>My problem is with creating a database. It is created too late and causes problems with further queries. I tried to use async and await but it seems it doesn't solve the problem.</p>
  <pre><code>async function storeDailyDealToDB(dailyDeal) {
      const db = new sqlite3.Database('database.db');
  
      await new Promise((resolve) =&gt; {
          const QUERY_CREATE_TABLE =
              &quot;CREATE TABLE IF NOT EXISTS daily_deal ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT,)&quot;;
          db.run(QUERY_CREATE_TABLE);
          resolve(&quot;done&quot;)
      });
  
      await new Promise((resolve) =&gt; {
          const insert =
              &quot;INSERT INTO daily_deal (title) VALUES (?)&quot;;
          const stmt = db.prepare(insert);
          stmt.run([dailyDeal['title']]);
          stmt.finalize();
          resolve(&quot;done&quot;)
      });
  
      let lastRow = await new Promise((resolve) =&gt; {
          db.each(&quot;SELECT * FROM daily_deal ORDER BY id DESC LIMIT 1&quot;, function (err, row) {
              resolve(err == null ? {} : row)
          });
      });
  
      db.close();
  
      return lastRow
  }
  </code></pre>
  <p>Here is the error I get:</p>
  <pre><code>[Error: SQLITE_ERROR: no such table: daily_deal
  Emitted 'error' event on Statement instance at:
  ] {
    errno: 1,
    code: 'SQLITE_ERROR'
  }
  
  Node.js v17.9.0
  </code></pre>
  <p>I did a lot of research and I am stuck. I read to use <code>Promise</code> but it works partially. I am not sure how to tackle this problem.</p>