Skip to content

Instantly share code, notes, and snippets.

@yagop yagop/index.js
Last active Jun 27, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.