title: How to send a file when getting it with request?
body: <p>I am making a request with a mandatory request and I need to send the response to the immediate user. I mean, I need to send the data just when I receive it.</p>
  <p>I want request to make the request and as it obtains the data, it will send it to the user in real time.</p>
  <p>I have the following code and all I can do in this way is save the file and then send it, which does not work at all well, because it takes even longer to send the file</p>
  <pre class="lang-js prettyprint-override"><code>const def = (req,res)=&gt; {
      const request = request.get(&quot;url&quot;)
      const getFile = fs.createWriteStream(&quot;path&quot;)
      
      request.on(&quot;error&quot;, ()=&gt; {
          res.send(&quot;error&quot;)
      })
      request.pipe(getFile)
  
      getFile.on(&quot;finish&quot;, ()=&gt;{
  
          const sendFile = fs.createReadStream(&quot;path&quot;)
          sendFile.on(&quot;data&quot;, (chunk)=&gt;{
          
              res.send(chunk)
          })
  
          sendFile.on(&quot;finish&quot;, ()=&gt; {
  
             res.end()
          })
      })
  
  }
  </code></pre>
  <p>This works but has several problems.</p>
  <ol>
  <li>I need to save the file</li>
  <li>Until it is downloaded to the server, it cannot be sent</li>
  <li>It is much slower than sending it in real time</li>
  </ol>
  <p>I need something maybe like the following (I know that this does not exist in such a way but I try to give an idea)</p>
  <pre><code>
  request.on(&quot;data&quot;, (chunk)=&gt;{
      res.send(chunk)
  })
  
  request.on(&quot;finish&quot;, ()=&gt; res.end())
  
  //or
  
  getFile.on(&quot;data&quot;, (chunk)=&gt;{
  
      res.send(chunk)
  })
  
  getFile.on(&quot;finish&quot;, () =&gt; res.end())
  
  </code></pre>
  <p>Please help me</p>