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

157
Views
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
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!