I think it’s ok to just think of singleFileUpload() as randomFunctionReturningSomething().
In the Promise, this function is called. It uploads a file and returns a response. The promise says that once the file upload completes, the parent function (upoloadToS3) should simply return a string containing a download URL.
If you want to see the full code, I’ll paste it below. The code works, I just wanted to remove the Promise as the rest of my app uses async/await instead of Promises.
Right, what I’m saying is there are no promises to await in that block of code.
return new Promise((resolve, reject) => {
return singleFileUpload(req, res, err => {
if (err) return reject(err)
return resolve(downloadUrl)
})
})
This block right here is wrapping the callback-based asynchronous upload function in a Promise, so that you can await it later, as I showed in my last comment. Again, await is a replacement for chaining then.
I just looked back at your initial question. await is an API used for interacting with promises (it literally waits for the result of the promise, then continues execution), so the premise of your question doesn’t really make sense.
For anyone else confused about Promises, I figured out what was so puzzling to me. In Javascript, the fetch API alread has a built in Promise, so you can use .then with it, without seeing any “Promise” text in any code. Axios and Mongoose also have built in Promises. This caused me to be very confused about when I could and couldn’t use “.then”.