I wrote an async function that needs to call a program in the server and that program generate a file which needs to load in UI for displaying. I am not sure how to show the result in my UI since execFile is async function and it may take few second results to be ready?
Do I need to have kind of infinity loop to check the result is ready in the server?
I am using nodejs-express handlebars.
router.post('/',function(req, res, next) {
const child = execFile('program.exe', ['in.sql'], (error, stdout, stderr) => {
if (error)
{
console.log(error);
return error;
}
else
{
// TODO: how to send the result to UI?
console.log(stdout);
}
});
return res.sendStatus(200);
});