title: Node JS - How to wait until a file exists on Google Cloud Storage Bucket, and then download file
body: <p>My team and I have tried numerous methods to solve this problem, but whenever we go to download the file, we get an error stating the file does not exist.</p>
  
  <p>What is the typical way to do this. This seems like something that should be easy,  but I can't seem to find anything that works.</p>
  
  <p>To clarify, my Node JS runs a function that uploads a file to one bucket. This triggers a cloud function which does some processing and then uploads a file to another bucket. I want Node JS to wait for that other file to be uploaded, and then download the file.</p>
  
  <pre><code>const storage = new Storage();
  const bucket = storage.bucket('receipttext');
  
  
  async function uploadFile() {
      await storage.bucket("BUCKET_ONE").upload('FILE_PATH', {
          gzip: true,
          metadata: {
              cacheControl: 'public, max-age=31536000',
          },
      });
      console.log('step1!');
      const options = {
          destination: 'DOWNLOAD_PATH',
      };
  
      //Something needs to go here to cause Node JS to wait until the file exists
      let file = null;
      let ifExist = false;
      while(!ifExist) {
          console.log('step1.1!');
          file = await storage
              .bucket("BUCKET_TWO")
              .file('FILE_NAME');
          ifExist =  file.exists();
          //console.log('step1.2!',ifExist);
          console.log('step2!');
      }
  
  
      //Downloads the File
      await file.download(options).catch(function(error){
              console.log(2);
          });
      console.log(
          `gs:// downloaded .`
      );
      console.log('step3!');
      let obj = JSON.parse(fs.readFileSync('DOWNLOAD_PATH', 'utf8'));
      console.log(obj,"here");
  
      res.json({response: obj});
  }
  uploadFile().catch(console.error);
  console.log("successUpload");
  </code></pre>