Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

758
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda