I'm trying to make a progress bar to monitor a Tesseract.recognize() call but when I try sending an update to change the progress bar I get this error:
[ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
This is what's running in the routes.js file:
Tesseract.recognize(
'/app/'+statistic.path_out_new
,'eng'
, { logger: m => {
console.log(m);
res.render('pages/uploadPicture.ejs', {
user : req.user
,progress : m
});
} }
)
.then(({ data: { text } }) => {
res.render('pages/uploadPage.ejs', {
user : req.user
,progress : text
});
});
Here is the relevant part of the HTML from the EJS template, uploadPage.ejs:
<section><div></div><progress value="<%=progress.progress%>" text="<%=progress.status%>" /></section>
I have read this question and I think the problem is caused by sending multiple headers every time there is an update to the progress bar, but how do I send information about how the function is progressing to the user (so that the progress bar updates) without sending a header, too? I tried res.write() as suggested here but that let to the progress bar page timing out, not updating.