Skip to content

Instantly share code, notes, and snippets.

@cpq
Created March 8, 2021 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpq/116fb13aaffda9a0693d81e9770d9c74 to your computer and use it in GitHub Desktop.
Save cpq/116fb13aaffda9a0693d81e9770d9c74 to your computer and use it in GitHub Desktop.
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