Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

753
Views
Fastify Error: ERR_AVVIO_PLUGIN_TIMEOUT: Plugin did not start in time

I'm following a Fastify tutorial, everything has been going well so far (connected to Database, routes working, etc.) however when attempting to add the notesDAL I'm receiving the following error:

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

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.

notes.js

"use strict";

const NotesDAL = require("./notesDAL");

module.exports = async function (fastify, opts) {
  const notesDAL = NotesDAL(fastify.db);
  fastify.route({
    method: "POST",
    url: "/",
    handler: async (request, reply) => {
      const { title, body } = request.body;
      const newNote = await notesDAL.createNote(title, body);
      return newNote;
    },
  });
};

notesDAL.js

const NotesDAL = (db) => {
  const createNote = async (title, body) => {
    const { id } = await db.one(
      "INSERT INTO notes (title, body) VALUES ($1, $2) RETURNING id",
      [title, body]
    );
    return { id, title, body };
  };
  return { createNote };
};
module.exports = NotesDAL;

If it matters, the folder structure is:

/app.js
/plugins/db.js
/routes/notes/notes.js
/routes/notes/notesDAL.js

Edit:

I've gotten it working however I am sure it's not the right way to do things, it looks very odd.

notesDAL.js

const NotesDAL = (db) => {}

updated to:

const NotesDAL = async (db) => {}

notes.js

const newNote = await notesDAL.createNote(title, body)

updated to:

const newNote = await (await.notesDAL).createNote(title, body)

As I mentioned, this looks bad but appears to be working. I'd still like to know a better method of doing this.

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Turns out that by creating the project with fastify-cli I was using fastify-autoload which prevented this from working.

AutoLoad can ignore the DAL files by adding the following to app.js when it registers AutoLoad:

ignorePattern: /.*(DAL).js/,

It then works successfully. Alternatively, I can move notesDAL.js to a folder called services and it works. So the folder structure would be:

/app.js
/plugins/db.js
/routes/notes/notes.js
/services/notesDAL.js
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!