title: callback function in transform stream node js
body: <p>Its a simple example of transform stream node js.</p>
  
  <p>Code :</p>
  
  <pre><code>const { Transform } = require('stream');
  
  const transtream = new Transform({
      transform(chunk, encoding, callback){
          this.push(chunk.toString().toUpperCase());
          callback()
      }
  });
  
  process.stdin.pipe(transtream).pipe(process.stdout);
  </code></pre>
  
  <p>This works fine:</p>
  
  <pre><code>Input: hi this is me
  Output: HI THIS IS ME
  Input: hi this is me again
  Output: HI THIS IS ME AGAIN
  </code></pre>
  
  <p>Now if i do not call the callback function, this program does not works as before.</p>
  
  <p>New code: </p>
  
  <pre><code>const { Transform } = require('stream');
  
  const transtream = new Transform({
      transform(chunk, encoding, callback){
          this.push(chunk.toString().toUpperCase());
          //callback()
      }
  });
  
  process.stdin.pipe(transtream).pipe(process.stdout);
  </code></pre>
  
  <p>Now when i give input, it works for the first time, then it stops transforming the data. so no output 2nd input onwards.</p>
  
  <pre><code>Input: hi this is me
  Output: HI THIS IS ME
  Input: hi this is me again
  Input: hey
  </code></pre>
  
  <p>Question: Why callback is needed? and why the program changes behavior when it is not called?</p>