Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

757
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda