'Execute when both(!) events fire .on('end')

I have a node app that reads two files as streams. I use event.on('end') to then work with the results. The problem is I don't really know how I can wait for BOTH events to trigger 'end'.

What I have now is:

    reader1.on('end', function(){
        reader2.on('end',function(){ 
          doSomething();
        });
    }); 

With small files this works, but if one of the files is very large the app aborts.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source