Node.js 等待http请求完成,然后在nodejs中继续循环

Node.js 等待http请求完成,然后在nodejs中继续循环,node.js,Node.js,我不知道怎么做。我开始学习javascript。 有人能帮我吗?这是我的密码: let url = "https://drive.google.com/uc?export=download&id=driveid"; while(true) { let check = false; console.log(url); const request = https.get(url, (response) => { if(type

我不知道怎么做。我开始学习javascript。 有人能帮我吗?这是我的密码:

let url = "https://drive.google.com/uc?export=download&id=driveid";
   while(true) {
      let check = false;
      console.log(url);
      const request = https.get(url, (response) => {
         if(typeof response.headers['Content-Disposition'] !== "undefined") {
            const file = fs.createWriteStream("a3.mp4");
            response.on('data', (chunk) => {
               file.write(chunk);
            }).on('end', async () => {
               file.end();
               check = true;
            })
         } else {
            let str = "";
            response.on('data', (chunk) => {
               str += chunk;
            }).on('end', () => {
               url = get_confirm_download_url(str);
               if(!url) {
                  console.log("Can\"t find download link");
                  check = true;
               }
            })
         }
      });
      if(check) break;
   }

我真的需要你的帮助

我不确定我是否掌握了正确的方法,但我对你的代码做了一些假设。试试这个:

let url='1〕https://drive.google.com/uc?export=download&id=driveid'
让check=true//告诉应用程序我们可以检查
while(检查){
check=false//在应用程序检查时设置为false
console.log(url)
https.get(url,(响应)=>{
if(响应的类型.标题['Content-Disposition']!='undefined'){
const file=fs.createWriteStream('a3.mp4')
响应
.on('数据',(块)=>{
file.write(块)
})
.on('end',async()=>{
file.end()
check=true//Done–告诉应用程序再次检查是安全的
})
}否则{
设str=''
响应
.on('数据',(块)=>{
str+=chunk
})
.on('end',()=>{
url=获取\确认\下载\ url(str)
如果(!url){
console.log('找不到下载链接')
check=true//Done–告诉应用程序再次检查是安全的
}
})
}
})
//不用休息了
}
当然有更好的方法可以做到这一点,但在我看来,这就是你想要做的。

您想获得什么?添加问题描述以获得准确的帮助。