Running three bash commands through a Node.js code snippet. Here's a portion of the script:
exec(str,
function(error, stdout, stderr){
console.log('stdout:'+stdout);
console.log('stderr:'+stderr);
if(error!=null){
console.log('exec error: '+error);
}
exec('bash create_q_out_list.sh',
function(error, stdout, stderr){
console.log('stdout:'+stdout);
console.log('stderr:'+stderr);
if(error!=null){
console.log('exec error: '+error);
}
exec('bash replaceString.sh',
function(error, stdout, stderr){
console.log('stdout:'+stdout);
console.log('stderr:'+stderr);
if(error!=null){
console.log('exec error: '+error);
}
});
});
});
The 'bash replaceString.sh' command generates an HTML file that is displayed in an Iframe on my website's homepage. However, there are instances where the old file is shown before the new one is fully generated by the 3rd bash command. This results in displaying incorrect content even though the correct HTML content is present.
Below is the Iframe section:
<iframe id='svg_frame' src="http://127.0.0.1:3000/render.html"></iframe>
Additionally, here is a segment of my server code (render.html is the file being created by the 3rd bash command):
app.get('/render.html', (req, res) =>{
const rend = fs.readFileSync('./render.html');
res.statusCode = 200;
res.setHeader = ('Content-Type', 'text/html');
res.write(rend);
res.end();
});
I need to ensure that the Node.js script waits for the new render.html file to be completely generated before rendering it on the Iframe.