title: How to make a function with events and pipe in nodejs
body: <p>I'm writing a nodejs library in typescript, the main scope of this library is gonna be downloading stuff from a given url, what I'd like it to do is to be used like this</p>
  
  <pre class="lang-js prettyprint-override"><code>import library from 'library'
  
  library('https://www.example.com')
      .on('progress', (progress: progress) =&gt; {
          //do something with the progress
      })
      .on('end', () =&gt; {
          //do something when done
      })
      .pipe(fs.createWriteStream('./test/file.mp4'))
  </code></pre>
  
  <p>I've never worked with node events and stream in such a way so I have no idea how to even go about this I'm using typescript and webpack also please forgive bad English</p>