Can I use res.send() node.js method inside the loop?
as first answer you can do something like.
app.get("/repeat/:word/:times", function(req, res){
var word = req.params.word;
var times = parseInt(req.params.times);
for(var i = 1; i<= times; i++){
word = ' ' + word;
}
res.send(word);
});
if you want a streaming api the look this documentation server-send-events(sse)
No.
Look at the documentation:
Sends the HTTP response
You can't have multiple responses to a single request.
Build a single response body in a variable as you loop. Send it once the loop is finished.