Created
March 8, 2021 15:30
-
-
Save cpq/116fb13aaffda9a0693d81e9770d9c74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const port = 8002; | |
const http = require('http'); | |
const http_handler = function(req, res) { | |
let request = '', count = 0; | |
req.on('data', chunk => request += chunk); | |
req.on('end', function(ev) { | |
res.writeHead(200); | |
const f = function() { | |
res.write('hi\n'); | |
if (count++ >= 10) { | |
res.end(); | |
} else { | |
setTimeout(f, 500) | |
} | |
}; | |
setTimeout(f, 500); | |
}); | |
}; | |
http.createServer(http_handler).listen(port, function(err) { | |
if (err) return console.log('Error starting server:', err); | |
console.log(`Server is listening on port ${port}`) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment