Looking for a general pointer on how to show live console output in a window using Handlebars

Using Handlebars, express, and node.js; I’ve got a shell script that’s triggered after an HTML form is filled out. The script — which runs on the server — outputs nicely via console.log:

builder.stdout.on('data', function(data) {
    console.log('stdout: ' + data);

The console shows exactly what it should. However, I need to feed that output in (near) real-time to the client in a window so [s]he can watch the progress of the script. I have the following in my template:

    <fieldset style="width:1200px" id="outputWindow">

    ... want the output text here ...


I’ve searched for a “clean” way to implement redirection to a client browser but thus far have been unsuccessful in finding one; most of what I’ve found revolves around polling updates, and I’d prefer to avoid that. Not asking for a complete solution, but can someone point me in the general direction of an accepted way to redirect this asynchronous output so that it will display on the client’s browser in that area?



To show realtime output of console.log in browser you have many ways.

The first way is using websocket.

Can you see example how to implement server side and client side: https://github.com/websockets/ws/tree/master/examples

But if you want to receive only output of console.log I advise you to use EventSource

Can you see example how to implement server side and client side: https://github.com/EventSource/eventsource/tree/master/example