title: How to write data stream to json file using node.js
body: <p>I am using node-osmosis to scrape some data from a website. I want to write the data to the json file. But it seems the data is keep comming and the file only write at the first time. I am using node-jsonfile to write data  to file. By the way there is a end function when the scraping is done. But I have tried it, and if it encounter a error the done will never be called and the data is lost.</p>
  
  <pre><code>osmosis
  .data(function(listing) {
      jsonfile.writeFileSync(file, listing);
  })
  </code></pre>
  
  <p>So how to write new data into the file?</p>