Skip to content

Instantly share code, notes, and snippets.

@artze
Created June 9, 2019 06:34
Show Gist options
  • Save artze/43b594c785ec628624d01c3822ee3b9e to your computer and use it in GitHub Desktop.
Save artze/43b594c785ec628624d01c3822ee3b9e to your computer and use it in GitHub Desktop.
Basic example of writable stream in http server
const Chance = require('chance');
const http = require('http');
const chance = new Chance();
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
while(chance.bool({ likelihood: 95 })) {
res.write(chance.string() + '\n');
}
res.end('\n The end... \n')
res.on('finish', () => {
console.log('All data was sent')
})
})
.listen(3000, () => {
console.log('Listening on port 3000');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment