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
x
7
1
const fs = require('fs').promises;
2
3
async function loadMonoCounter() {
4
const data = await fs.readFile("monolitic.txt", "binary");
5
return new Buffer(data);
6
}
7
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).