I want the console to print '1' first, but I am not sure how to call async functions and wait for its execution before going to the next line of code.
const request = require('request');
async function getHtml()
{
await request('https://google.com/', function (error, response, body) {
console.log('1');
});
}
getHtml();
console.log('2');
Of course, the output I'm getting is
2
1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…