0

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:

const fs = require('fs').promises;

async function loadMonoCounter() {
    const data = await fs.readFile("monolitic.txt", "binary");
    return new Buffer(data);
}

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

JeffSpicoli
  • 101
  • 1
  • 8
  • `readFile` already returns a Promise that you can compose. The returned promise wouldn't be a member – sinanspd Jun 25 '21 at 04:32

1 Answers1

0

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).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335