CLI real time update NodeJS similar to “Top” command?

39 views
Skip to first unread message

Mohammed S Fadin

unread,
Oct 16, 2014, 7:35:32 PM10/16/14
to nod...@googlegroups.com

Any idea/tips on how to implement a real time-esh update feature similar to linux TOP command in Node.JS?

My implementation is something like the following:

fs.watchFile(filepath, someFunction);

someFunction(curr, prev){
  // Create a child process and run tail command 'tail -f path/to/file'
  // Let tail.stdout listen to data event and inside it
      process.stdout.write('\033c'); // Reset Terminal every time on file change
      process.stdout.write(data);
}

Is there any better implementation or package that could assist in implementing this feature? Since watchFile() is slow.

Please note that fs.watch() works only one time, then it never make any callbacks/triggers on file change.

Thanks in advance!

Reply all
Reply to author
Forward
0 new messages