https://github.com/sreehari2003/tail-f
Implementation of linux command tail -f in node js
https://github.com/sreehari2003/tail-f
filewatcher nodejs tail-f
Last synced: 4 months ago
JSON representation
Implementation of linux command tail -f in node js
- Host: GitHub
- URL: https://github.com/sreehari2003/tail-f
- Owner: sreehari2003
- Created: 2023-12-22T16:17:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-22T16:18:59.000Z (over 1 year ago)
- Last Synced: 2024-12-20T07:45:17.273Z (6 months ago)
- Topics: filewatcher, nodejs, tail-f
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Tail -f
### this is a mocking of tail -f linux command written in node js when ever the file changed the changes are updated in client side
## Uses Eventsource in client side to check for updates
files changes are read via node js fs api
```js
const tail = fs.watch(p, (type, file) => {
// on file change
if (type === "change") {
const lines = tailLog(p, 10);// Send each line as an event to the client
lines.forEach((line) => {
res.write(`data: ${line}\n\n`);
});
}
```Event source api is used in client side
```js
const eventSource = new EventSource("http://localhost:8080/tail");const outPut = document.querySelector(".tail");
eventSource.addEventListener("message", (event) => {
outPut.innerHTML += event.data + "\n";outPut.scrollTop = outPut.scrollHeight;
});```