title: How can I make an axios stream read + file write synchron?
body: <p>I try get a file and rename it.</p>
  <p>I get the error:</p>
  <pre><code>Error: ENOENT: no such file or directory, rename './tmp.png' -&gt; './tmp2.png'
  </code></pre>
  <p>The reason is createWriteStream is not finished if renameSync is called! File './tmp.png' not exist! How can I make the file reading synchron?</p>
  <pre><code>const axios = require(&quot;axios&quot;);
  const fs = require(&quot;fs&quot;);
  
  let url = &quot;https://upload.wikimedia.org/wikipedia/commons/7/77/Friedrich_II._Schwertgroschen_1456_bis_1461%2C_Vorderseite%2C_CNG.PNG&quot;
  
  async function main (){
      await axios({
          method: &quot;get&quot;,
          url: url,
          responseType: &quot;stream&quot;,
      })
          .then(async (res) =&gt; {
  
              const writer = fs.createWriteStream(&quot;./tmp.png&quot;)
              await res.data.pipe( await writer )
  
              writer.on('finish', () =&gt; console.log(&quot;Finished&quot;));
              writer.on('error', () =&gt; console.error(&quot;Error while dowloading image&quot;));
          })
          .catch((err) =&gt; console.log(err));
  }
  
  
  main()
  
  fs.renameSync(&quot;./tmp.png&quot;, &quot;./tmp2.png&quot;, () =&gt; {
      console.log(&quot;\nFile Renamed!\n&quot;)
  });
  
  
  console.log(&quot;end program&quot;)
  </code></pre>