I am trying to create multiple DB connections. The problem is in order to get the DB connection string, I have to call an asynchronous function (getDBString). This asynchronous function returns the correct DB string. After that, I have to export the connection variables. I have a doubt. Will the conn1, conn2, and conn3 variables are assigned correct values coming from the async functions? or will they be unassinged when exporting? I am a newbie and can anyone explain when these callbacks run and when the export statement runs?
import mongoose from 'mongoose';
import dbConfiguration from '../config';
import DBString from '../utils/DBString';
let conn1 = DBString.getDBString(dbConfiguration.endpoint1).then( connString => mongoose.createConnection(connString, {}));
let conn2 = DBString.getDBString(dbConfiguration.endpoint2).then( connString => mongoose.createConnection(connString, {}));
let conn3 = DBString.getDBString(dbConfiguration.endpoint3).then( connString => mongoose.createConnection(connString, {}));
export {conn1 ,conn2 ,conn3}