I have to export a result of async
function from a Javascript file. Right now, When I export it, I am getting a promise which needs then()
function in each file wherever we want to import that file. Due to this issue, I need to resolve the exported results in each file where we are importing it. I simply want the results of the async
operation not the promises. How can we achieve it ?
mainfile.js
const getAllDatabases = async(dbconnection) => {
const results = await dbconnection.query(
`SELECT name FROM master.dbo.sysdatabases`
);
return results;
}
module.exports = getAllDatabases();
otherfile.js
const mainfile = require("mainfile");
mainfile.then((reponse)=>{
reponse[db].Table.Operation();
});