How to deal with promise within express.js file using lambda

First of all, I am not sure if I am using Promise correctly but I am requesting a promise and storing it in a variable called tokenPromise. The resolved promise value (access token) has to be sent along with every request. Therefore, I wrapped around all of my requests with IIFE and resolved tokenPromise inside that wrapper, saved it in a variable called credentials and passed that value into every request.

Now, I was able to call simple non-asynchronous calls using lamba but I am not sure how I would handle a case described above. Any guidance would be appreciated! Thank you!

Hi, do you have this in a repo so I can see the full file? What is the rp function you wrapped the POST in? Also the IIFE doesn’t seem to close properly, you have to wrap the function in () then include () at the end so it’s more like:

(async function() {

I don’t see the ending of the function in your example. It would be easier to debug if you share the full file or repo. You also shouldn’t need to resolve the function yourself if you await it, but i’m not sure which library you’re using to make the request so I can’t be sure. If it’s promise based then you can just call it with await and the library should resolve it’s own promise and return the result or throw an error by sending a rejection.