Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express')
- var app = express()
- app.listen(1337)
- app.all('/stream/:chunks', function (req, res, next) {
- res.writeHead(200, {
- 'Content-Type': 'text/plain',
- 'Transfer-Encoding': 'chunked'
- })
- // set default chunks to 10
- var chunks = req.params.chunks || 10
- // max out chunks at 100
- if (chunks > 100) chunks = 100
- var count = 1
- while (count <= chunks) {
- res.write(JSON.stringify({
- type: "stream",
- chunk: count++
- })+'\n')
- };
- res.end()
- next()
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement