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

160
Visualizações
dinamically require from db with node.js

I gota mysql table in which are stored the available plugins for some users. I've written a function that mounts all the plugin routes and it goes like this (leaving error handling and file checking) :

var requireEnrolPlugins = function(app){
connection.query('Select name FROM ... where type = ?,[enrol],
(err,rows,fields) => {
async.eachOfSeries(rows,function(item,key,eachOfCallback){
require('path/to/plugin-dir/ ' + item.name + '/routes.js')(app);
eachOfCallback();
})
})
}

this function is called in a index.js file where all the routes are mounted, then the index.js file is declared in the app.js main file If i try to require without the appEngine handler, it goes ok. But if I add the (app) engine at the and of the require, it throws this error:

require(...) is not a function
at C:\Users\username\Desktop\node-
projects\project\functions\general_functions.js:70:33
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)
about 4 years ago · Santiago Trujillo
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