0
async function someFunction() {
    try {
      var key =  await dec.awsDecrypt('dev-frontend')
      return key;
    } catch(err) {
    }
}

//calling the function 
const result = someFunction()

Above I have an asynchronous that returns the value key. I'm trying to retrieve that value by assigning the function to a variable result, but when trying I get Promise { <pending> } as a response. Any suggestions?

Push_king
  • 11
  • 1

1 Answers1

0

Your someFunction will return a promise because you put the async keyword before it.

You are going to need to await it as well.

const result = someFunction().then(console.log)

or

const result = someFunction().then((result)=>console.log(result))    

or you can run the whole program inside what is called an immediately invoked function. That way you can make your immediately invoked function async as well and use await in there.

MarkCBall
  • 229
  • 1
  • 4