The asynchronous process of Node crawler is difficult to control. How can it be modified to the form of Promise or Async/Await

  node.js, question

The following code, I want to print out the final ans array, it is very difficult to print, because the printing operation is synchronous, always printing is empty, for asynchronous process control, how should the form of Promise or Async/Await be modified?

const cheerio = require('cheerio');
 const http = require('http');
 const iconv = require('iconv-lite');
 
 let baseUrl =  "http://www.ygdy8.net/html/gndy/dyzz/list_23_" ;
 let Host =  "http://www.ygdy8.net/" ;
 
 const totalPage = 2;  //Specify how many pages of data to crawl
 let ans = [];
 //Get page movie data
 function getTitleHref(url,page) {
 Letstartral = url plus page plus ".html";
 http.get(startUrl,function(res) {
 const { statusCode } = res;
 let chunks = [];
 res.on('data',function(chunk){
 chunks.push(chunk);
 });
 res.on('end',function(){
 let title = [];
 
 let html = iconv.decode(Buffer.concat(chunks),'gb2312');
 let $ = cheerio.load(html, {decodeEntities: false});
 // console.log($);
 $('.co_content8 .ulink').each(function(i,d) {
 let $d = $(d);
 let titleHref = [];
 titleHref.push({
 href: $d.attr('href')
 });
 getLink(titleHref,(ans)=>{console.log(ans)})
 });
 // console.log(ans);
 });
 });
 bracket
 
 
 // /*
 //Get Seed Links
 function getLink(titleHref,cb) {
 Log ('enter getLink');
 console.log(titleHref);
 if(titleHref) {
 titleHref.forEach(function(v,k) {
 console.log('~~~~~~~~~~~~~~~~~~~~');
 Let infoUrl = Host plus v.href;
 // console.log(infoUrl);
 
 http.get(infoUrl,function(res) {
 const { statusCode } = res;
 const contentType = res.headers['content-type'];
 
 let error;
 if (statusCode !  == 200) {
 Error = new Error ('request failed.  \n' plus
 `Status Code: ${statusCode} `);
 bracket
 if (error) {
 console.error(error.message);
 //Consume response data to free up memory
 res.resume();
 return;
 bracket
 Log ('enter getlink http');
 let chunks = [];
 res.on('data',function(chunk) {
 chunks.push(chunk);
 });
 res.on('end', function(){
 try {
 let html = iconv.decode(Buffer.concat(chunks),'gb2312');
 let $ = cheerio.load(html, {decodeEntities: false});
 let bt = '';
 bt = $('#Zoom td').children('a').attr('href');
 // console.log(bt);
 // console.log(typeof bt)
 ans.push(bt);
 cb(ans);
 }catch (e) {
 console.error('bt',e.message);
 bracket
 })
 }).on('error', (e) => {
 Console.error (`error: ${e.message} `);
 });
 });
 bracket
 };
 // */
 for(let i = 1;   i <= totalPage;  I plus)
 getTitleHref(baseUrl,i);
 };

Encapsulating http.get throws a Promise instance, resolve in the end event and reject in the error event.
Change forEach to Promise.all plus map
Await Promise.all is the result you want.