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 data
nor end
events are called. How can I detect when this is the case in the node.js code?
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:
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();