Skip to content

Instantly share code, notes, and snippets.

@yagop
Last active June 27, 2017 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yagop/0ddf36d3042cc66017fceb7af7b1bd21 to your computer and use it in GitHub Desktop.
Save yagop/0ddf36d3042cc66017fceb7af7b1bd21 to your computer and use it in GitHub Desktop.
Stream server
const ts = require('tail-stream')
const http = require('http')
const PORT = 1234
const HOST = '0.0.0.0'
const FILE = 'info.log'
const server = http.createServer((req, resp) => {
const tstream = ts.createReadStream(FILE, {
beginAt: 0,
onMove: 'stay',
detectTruncate: true,
onTruncate: 'reset',
endOnError: true
})
resp.setHeader('Content-Type', 'text/plain')
tstream.pipe(resp)
})
server.timeout = 0
server.listen(PORT, HOST, (err) => {
if (err) {
console.error(err)
process.exit(1)
} else {
console.log(`server is listening on ${PORT}`)
}
})
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"tail-stream": "0.3.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment