You can't magically make an async operation into a synchronous operation in Javascript. So, an async operation will require async coding techniques (callbacks or promises). The same is true in regular coding as in module startup/initialization.
The usual design pattern for dealing with this issue is to give your module a constructor function that you pass a callback to and when you call that constructor function, it will call the callback when the async result is done and then any further code that uses that async result must be in that callback.
Or, since you're already using promises, you can just export a promise that the calling code can use.
// fileA.js
module.exports = Promise.all(allConnectionPromises);
Then, in code that uses this:
require('./fileA').then(function(theModels) {
// access theModels here
}, function(err) {
console.log(err);
});
Note, when doing it like this, the exported promise serves as a convenient cache for theModels
too since every other module that does require('./fileA')
will get the same promise back and thus the same resolved value without re-executing the code behind getting the models.
Though I think the promises version is probably cleaner especially since you're already using promises within the module, here's what the constructor version would look like for comparison:
// fileA.js
var p = Promise.all(allConnectionPromises);
module.exports = function(callback) {
p.then(function(theModels) {
callback(null, theModels);
}, function(err) {
callback(err);
});
}
Then, in code that uses this:
require('./fileA')(function(err, theModels) {
if (err) {
console.log(err);
} else {
// use theModels here
}
});