I have a file creator block which writes the file to disk, and then sends the file to the client.
But the response is sent before the file is getting written.
carbone.render("./template.odt", data, options, (err, ress) => {
if (err) {
return console.log(err);
}
var paths = `./static/reports/report-${timestamp}.pdf`;
fs.writeFileSync(paths, ress);
process.exit();
});
res.sendFile(
path.join(__dirname, "..", "static", "reports", `report-${timestamp}.pdf`)
);
What is the solution so that sendFile waits for the file to be written and then fetches it?