Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node server that streams dummy content for a number of seconds, useful for testing timeouts
const http = require('http');
const server = http.createServer(function (req, res) {
res.writeHead(200, {
"content-type": "text/plain",
"transfer-encoding": "chunked"
});
let i = 0;
const interval = setInterval(() =>{
res.write(String(i++));
console.log("seconds", i);
}, 1000);
setTimeout(() => {
clearTimeout(interval);
res.end();
}, 300 * 1000)
});
server.listen(3000, err => err ? console.error(err) : console.log("listening on 3000"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.