I am looking to continuously send data to the client in real-time from res.write, however, the current setup only allows for sending data once in one response. How can I modify this code to enable multiple responses and ensure the data is streamed live to the client?
app.get('/api/simulator', (req,res) => {
res.setHeader('Content-Type','text/html');
var spawn = require('child_process').spawn,
ls = spawn('../abc.sh');
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data.toString());
res.write(data.toString());
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data.toString());
});
ls.on('exit', function (code) {
console.log('child process exited with code ' + code.toString());
res.end();
});
});