Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
How to get resolved value of promise then export using module.exports?

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))
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda