How to get resolved value of promise then export using module.exports?

29 views Asked by At

I have this Promise snippet,

    let myPromise = new Promise(async function(resolve, reject){

    const defaultConfig = {
            s3: {
                region: process.env.ENV_S3_REGION,
                accessKeyId: await juice.string('S3.ACCESS_KEY_ID', juice.MANDATORY),
                secretAccessKey: process.env.ENV_S3_SECRET_ACCESS_KEY
            },
            uploadConfig: { 
                bucket: process.env.ENV_UPLOAD_BUCKET
            }
}
   resolve(defaultConfig);
}

And I'd like to module.export the defaultConfig object. So I did this at the end of the code,

myPromise.then(res => module.exports = res)

But when calling in on other file, it can't get the value, it gives me undefined. But if I console.log the res like, this I can output the value.

myPromise.then(res => console.log(res))
0

There are 0 answers