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

245
Vistas
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)
over 4 years ago · Santiago Trujillo
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