title: Using Fs/Node/Json2Csv To Add Rows to CSV
body: <p>I am streaming data off of Twitter's API, and am processing it on a node server I have set up. I am currently parsing the data so I have an object that looks like this: <code>{"name": //name, "tweet": //textofthetweet, "url": //tweetURL}</code></p>
  
  <p><strong><em>I would like to be able to add each of these objects as new line to a CSV file, adding a new line for every tweet I receive.</em></strong> </p>
  
  <p>Right now, I know how to create a single CSV every time I create this object. How do I tweak this code so that the new entry is added to the CSV file, rather than overwriting it?</p>
  
  <p>Here's the relevant bit of code:</p>
  
  <pre><code>var param =  {follow: 'a bunch of twitter ID's go here'
  var followIds = [//The same Twitter IDs go here //]
  twitterClient.stream('statuses/filter',param,function(stream) {
  stream.on('data', function(tweet) {
  
    // Variables used to store CSV update (and the CSV column names).
    var update = [];
    var columns = ["name","tweet","URL"];
  
    var i;
    for(i = 0; i &lt;followIds.length; i++){
      if(followIds[i] == tweet.user.id_str){ // if so, get contents
  
        var tweetURL = `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`
  
        let name = tweet.user.name;
        let tweetText = tweet.text;
  
        /////  PREPARE UPDATE TO CSV HERE //////
        update.push({"name": name, "tweet": tweetText, "url": tweetURL})
  
  
  
        ///// THIS PART OF THE CODE NEEDS TO CHANGE /////
        var csv = json2csv({ data: update, fields: columns})
          fs.writeFile('twitterData.csv',csv,function(err){
          if (err) throw err;
          console.log('File Saved')
        })
      }
       update = []; // Clear update here.
    }   
  })
  </code></pre>
  
  <p>Does anyone know how to do this, <em>preferably by making a small adjustment to my code</em>? Thank you very much!</p>