I'm trying to send multiple responses to client while computing. Here is my example:
app.get("/test", (req, res) => {
console.log('test');
setTimeout(() => {
res.write('Yep');
setTimeout(() => {
res.write('Yep');
setTimeout(() => {
res.write('Yep');
setTimeout(() => {
res.write('Yep');
setTimeout(() => {
res.write('Yep');
setTimeout(() => {
res.end();
}, 1000);
}, 1000);
}, 1000);
}, 1000);
}, 1000);
}, 1000);
});
I want to get the response in every seconds. But my code works and it send response on end()
. Is there any way to do it?