title: Node JS - How to write stream big json data into json array file?
body: <p>I have difficult to write a json data into json file using <code>stream</code> module.
  I learn about this from several blog tutorial, one of them is this <a href="https://www.sandersdenardi.com/readable-writable-transform-streams-node/" rel="noreferrer">page</a> </p>
  
  <p>Let say i am working with big json data on a json file. I think it is not possible to store all json object inside my memory. So i decided to do it using stream module.</p>
  
  <p>Here the codes i have done:</p>
  
  <p>writeStream.js</p>
  
  <pre><code>var Writable = require('stream').Writable,
  util = require('util');
  
  var WriteStream = function() {
      Writable.call(this, {
          objectMode: true
      });
  };
  
  util.inherits(WriteStream, Writable);
  
  WriteStream.prototype._write = function(chunk, encoding, callback) {
      console.log('write            : ' + JSON.stringify(chunk));
      callback();
  };
  
  module.exports = WriteStream;
  </code></pre>
  
  <p>readStream.js</p>
  
  <pre><code>var data = require('./test_data.json'),
  Readable = require('stream').Readable,
  util = require('util');
  
  var ReadStream = function() {
      Readable.call(this, {
          objectMode: true
      });
  
      this.data = data;
      this.curIndex = 0;
  };
  
  util.inherits(ReadStream, Readable);
  
  ReadStream.prototype._read = function() {
      if (this.curIndex === this.data.length) {
          return this.push(null);
      }
  
      var data = this.data[this.curIndex++];
      console.log('read             : ' + JSON.stringify(data));
      this.push(data);
  };
  
  module.exports = ReadStream;
  </code></pre>
  
  <p>Called with this code:</p>
  
  <pre><code>var ReadStream = require('./readStream.js'),
  WriteStream = require('./writeStream.js');
  
  var rs = new ReadStream();
  var ws = new WriteStream();
  rs.pipe(ws);
  </code></pre>
  
  <p>Problem: I want to write it into different file, how is it possible?
  Can you please help me?</p>