title: Fastify Error: ERR_AVVIO_PLUGIN_TIMEOUT: Plugin did not start in time
body: <p>I'm following a Fastify tutorial, everything has been going well so far (<em>connected to Database, routes working, etc.)</em> however when attempting to add the <code>notesDAL</code> I'm receiving the following error:</p>
  <p><code>Error: ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time: /routes/notes/notesDAL.js. You may have forgotten to call 'done' function or to resolve a Promise</code></p>
  <p>The code is exactly the same as the tutorial, so I assume it's perhaps outdated but I'm lost. I've tried a few different ways and seem to constantly face errors. Any assistance would be much appreciated.</p>
  <p><strong>notes.js</strong></p>
  <pre class="lang-js prettyprint-override"><code>&quot;use strict&quot;;
  
  const NotesDAL = require(&quot;./notesDAL&quot;);
  
  module.exports = async function (fastify, opts) {
    const notesDAL = NotesDAL(fastify.db);
    fastify.route({
      method: &quot;POST&quot;,
      url: &quot;/&quot;,
      handler: async (request, reply) =&gt; {
        const { title, body } = request.body;
        const newNote = await notesDAL.createNote(title, body);
        return newNote;
      },
    });
  };
  
  </code></pre>
  <p><strong>notesDAL.js</strong></p>
  <pre class="lang-js prettyprint-override"><code>const NotesDAL = (db) =&gt; {
    const createNote = async (title, body) =&gt; {
      const { id } = await db.one(
        &quot;INSERT INTO notes (title, body) VALUES ($1, $2) RETURNING id&quot;,
        [title, body]
      );
      return { id, title, body };
    };
    return { createNote };
  };
  module.exports = NotesDAL;
  
  </code></pre>
  <p>If it matters, the folder structure is:</p>
  <pre><code>/app.js
  /plugins/db.js
  /routes/notes/notes.js
  /routes/notes/notesDAL.js
  </code></pre>
  <hr />
  <p><strong>Edit:</strong></p>
  <p>I've gotten it working however I am sure it's not the right way to do things, it looks very odd.</p>
  <p><strong>notesDAL.js</strong></p>
  <pre class="lang-js prettyprint-override"><code>const NotesDAL = (db) =&gt; {}
  </code></pre>
  <p>updated to:</p>
  <pre class="lang-js prettyprint-override"><code>const NotesDAL = async (db) =&gt; {}
  </code></pre>
  <p><strong>notes.js</strong></p>
  <pre class="lang-js prettyprint-override"><code>const newNote = await notesDAL.createNote(title, body)
  </code></pre>
  <p>updated to:</p>
  <pre class="lang-js prettyprint-override"><code>const newNote = await (await.notesDAL).createNote(title, body)
  </code></pre>
  <p>As I mentioned, this looks bad but appears to be working. I'd still like to know a better method of doing this.</p>
  <p>Thank you.</p>