there is a folder models, controllers, routes. In these folders there are JS files of the following type:

module.exports = user = { add: function(firstName, lastName){ console.log(firstName, lastName) }, update: function(user){ console.log(user) } }; 

How to connect all the files at once? let's say

 var models = require("/models"); var controllers = require("/controllers"); var routes = require("/routes"); 

    1 answer 1

    Define files in folders index.js , in which to include all files.

    For example, if there is a module testcontroller.js in the controllers folder, create an index.js file in the controllers folder with the following content:

     module.exports.testcontroller = require('./testcontroller'); 

    Now, if you connect the controllers folder somewhere:

     var controllers = require("/controllers"); 

    You can also contact testcontroller :

     controllers.testcontroller.вызвать_какой_то_метод() 

    Or run all the files in the folder and connect. For example, the controllers folder:

     var normalizedPath = require("path").join(__dirname, "controllers"); require("fs").readdirSync(normalizedPath).forEach(function(file) { require("./controllers/" + file); }); 
    • thank you very much - Evgeniy Nikolaev
    • @ YevgenyNikolaev happy to help ^ _ ^ - Suvitruf