I have a program in Bash which runs a console feed. The feed is text, and is appended to each time an event happens and is timestamped.
How would I load the contents of the console feed onto a page (perhaps last 200 lines or so of the console), and send additional data each time the file was appended to (the new lines)?
I am completely new to WebSockets and the moving of dynamic data, so please explain anything thoroughly.
Note: I also have node.js installed.
Since you already have node.js, you should definitely check out socket.io; it’ll take care of all the WebSocket stuff for you. Check out the site to learn how to use it.
Also, since you’re interested in watching a file for changes, check out the
fs.watchFile()function of the FileSystem module of node.js. It’ll fire a callback every time a file is changed. You can use this to get the new data and pipe it to the browser usingsocket.emit().