Answer the question
In order to leave comments, you need to log in
Why is part of the script executed after the timer fires?
Why is all the text "Hello world!Hello is done!" displayed? after 5 seconds of the timer, instead of first "Hello world!" and then after 5 seconds "Hello is done!"?
let http = require(`http`);
let app = http.createServer((req, res) => {
res.writeHead(200);
res.write(`Hello world!`);
setTimeout(() => {
res.write(`Hello is done!`);
res.end();
}, 5000);
}).listen(8080);
Answer the question
In order to leave comments, you need to log in
```
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.setHeader('Transfer-Encoding', 'chunked');
res.writeHeader(200);
```
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question