title: Download File from public S3 bucket in Node.js
body: <p>How do I download a file uploaded on public S3 bucket with Node.js.</p>
  <p>I am trying to create HTTPS GET request and pipe its response into a writable file stream using:</p>
  <pre><code>
  import fs from 'fs';
  import https from 'https';
  
  downloadFile = async (url, fileName) =&gt; {
    return new Promise((resolve) =&gt; {
      https.get(url, (response) =&gt; {
        const file = fs.createWriteStream(`/tmp/${fileName}`);
        response.pipe(file);
        // after download completed close filestream
        file.on('finish', () =&gt; {
          file.close();
          resolve({});
          console.log(`${fileName} Download Completed`);
        });
      });
    });
  }
  </code></pre>
  <p>This function doesn't download a file in /tmp folder and doesn't console following:</p>
  <pre><code>console.log(`${fileName} Download Completed`);
  </code></pre>