title: Pausing a readable stream in Node.js
body: <p>I'm using <a href="https://github.com/Keyang/node-csvtojson" rel="noreferrer">csv-to-json</a>, a neat library to process CSV files.</p>
  
  <p>I've got a use case where I need to process a large (>2 million rows) CSV and insert it into a DB.</p>
  
  <p>To do this without running into memory issues, I intend to process the CSV as a stream, pausing the stream every 10000 rows, inserting the rows in my DB and then resuming the stream.</p>
  
  <p>For some reason I can't seem to <code>pause</code> the stream.</p>
  
  <p>Take for example the following code:</p>
  
  <pre><code>const rs = fs.createReadStream("./foo.csv");
  rs.pause();
  
  let count = 0;
  
  csv()
  .fromStream(rs)
  .on("json", (json) =&gt; {
    count++;
    console.log(count);
  })
  .on("done", () =&gt; {
    cb(null, count);
  })
  .on("error", (err) =&gt; {
    cb(err);
  })
  </code></pre>
  
  <p><code>count</code> is logged 200 times (that's how many rows I have in my CSV) - I was expecting it not to log anything since the stream is paused before passing it over to <code>fromStream()</code></p>