I'm interested in loading of my routers in nodejs express application. I saw the two approach:
The first is loading an all routers in a boot place of application like as the following:
module.exports = function(app, db) {
var controllers_path = __dirname + '/app/controllers';
var controller_files = fs.readdirSync(controllers_path);
controller_files.forEach(function(file){
require(controllers_path+'/'+file)(app)
})
});
};
The the second ones is loading of each router in a certain files if needed like as the following:
require('../controllers/main.js');
require('../controllers/payload.js');
Which approach is better for performance?
The first method seems more ok, since it's clear there that you would only block when booting up the application.
The same thing might happen the the 2nd approach, but it's not totally clear from the snippet.