Last active
May 31, 2017 06:44
-
-
Save FND/b0db6be61b71b19acf555171be0f9022 to your computer and use it in GitHub Desktop.
Express streaming sample
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
"use strict"; | |
let express = require("express"); | |
const LIPSUM = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; | |
let app = express(); | |
app.get("/", (req, res) => { | |
res.status(200); | |
let i = 0; | |
let emit = _ => { | |
res.write(`[${++i}] ${LIPSUM}\n`); | |
setTimeout(emit, 100); | |
}; | |
emit(); | |
setTimeout(_ => { | |
res.write("~~~ EOS ~~~\n"); | |
res.end(); | |
}, 2000); | |
}); | |
let server = app.listen(3000, () => { | |
let addr = server.address(); | |
// eslint-disable-next-line no-console | |
console.log(`→ http://${addr.address}:${addr.port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment