Created
June 9, 2019 06:34
-
-
Save artze/43b594c785ec628624d01c3822ee3b9e to your computer and use it in GitHub Desktop.
Basic example of writable stream in http server
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 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