title: Read and Write CSV using fast-csv package in Node.js
body: <p>I am trying to write a simple node program that reads a csv file, extracts a column (say second) and writes it to another CSV file. I am reading the contents to an array and then writing that array to file. </p>
  
  <p>Stages and data in each step</p>
  
  <p><strong>inputfile</strong></p>
  
  <pre><code>123,456,789,abc
  def,ghi,232,jkl
  </code></pre>
  
  <p><strong>array</strong></p>
  
  <pre><code>['456','ghi']
  </code></pre>
  
  <p><strong>outputfile</strong></p>
  
  <pre><code>4,5,6
  g,h,i
  </code></pre>
  
  <p><strong>output needed</strong></p>
  
  <pre><code>456
  ghi
  </code></pre>
  
  <p>Am i just missing a configuration or is the way i am writing data wrong? Is my block of code to write to file within END block not correct?</p>
  
  <p>Here is my code</p>
  
  <pre><code>var fast_csv = require('fast-csv');
  var tempArray=new Array();
  console.log("START");
  fast_csv.fromPath("inputfile.txt").on("data", function(data){
      tempArray.push(data[1]);  
  })
    .on("end", function(){
      tempArray.sort();
      console.log(tempArray);
  
      fast_csv.writeToPath("outputfile.csv", tempArray)
     .on("finish", function(){
        console.log("END");
     });
  
  }); 
  </code></pre>