Last active
June 27, 2017 11:56
-
-
Save yagop/0ddf36d3042cc66017fceb7af7b1bd21 to your computer and use it in GitHub Desktop.
Stream 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 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}`) | |
} | |
}) |
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
{ | |
"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