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