Skip to content

Implementation of linux command tail -f in node js

Notifications You must be signed in to change notification settings

sreehari2003/tail-f

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

   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

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;
});


About

Implementation of linux command tail -f in node js

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published