Skip to content
Advertisement

Is there a cleaner way to await an https.get?

I stumbled across this post while looking for a way to await reading a file with fs. I was surprised that I hadn’t seen it anywhere else:

JavaScript

Is there a way to use await in the same manner shown above, but for the 'https' library?

I didn’t see anything like .promises and I was hoping to avoid the whole return Promise resolve reject business.

Thank you

Advertisement

Answer

Is there a way to use await in the same manner shown above, but for the ‘https’ library?

No, but there are numerous third-party libraries which use promises by default (including axios, node-fetch, bent, got, superagent, and urllib).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement