title: node.js: How to detect an empty stdin stream?
body: <p>I have a node.js script/server that reads some input from stdin when its launched. However, sometimes there's no data to be passed in. This is troublesome because it seems like in this case neither the <code>data</code> nor <code>end</code> events are called. How can I detect when this is the case  in the node.js code?</p>
  
  <p>I'd like to avoid having to append special "end" characters at the end of the input, so as not to inconvenience the client. The associated code is below:</p>
  
  <pre><code>  var newHTML = '';
    var gfm = spawn(__dirname + '/node_modules/docter/bin/github-flavored-markdown.rb');
    process.stdin.on('data', function(chunk){
      gfm.stdin.write(chunk);
    });
    process.stdin.on('end', function(){
      gfm.stdin.end();
    });
    gfm.stdout.on('data', function(data) {
      newHTML += data;
    });
    gfm.on('exit',function(ecode){
      socket.emit('newContent', newHTML);
    });
    process.stdin.resume();
  </code></pre>