lucagrulla / node-tail

The zero dependency Node.js module for tailing a file
https://www.lucagrulla.com/node-tail/
MIT License
467 stars 76 forks source link

Problem with tailing textfile in Windows #137

Closed Zoro-6191 closed 3 years ago

Zoro-6191 commented 3 years ago

Hi, I'm not sure if I missed something or some extra step, but same code which gives good response on all of my linux systems doesnt give same result in windows

image that's literally all of the code

that console.log doesnt output anything at all unless I close the program which is writing to the log file.As soon as I quit the program thats writing to the log file, all of the log data gets printed to console at once. That behavior is exhibited only on windows. Same writing program on linux. And console.log output is perfect. Please let me know if I'm doing anything wrong. Thanks

lucagrulla commented 3 years ago

Hey,

I can't see anything wrong.

It's probably caused by fs.watch implementation, the nodejs core function used by tail, that doesn't have 100% compatibility across different OSes: https://nodejs.org/dist/latest-v14.x/docs/api/fs.html#fs_caveats

On Windows, you could try to use WatchFile instead of watch, by useWatchFile as a constructor parameter: https://github.com/lucagrulla/node-tail#constructor-parameters

I hope it helps.

Zoro-6191 commented 3 years ago

thanks for fast response my program will mostly be running on linux, so its fine I'll try switching to watchFile() for windows use, although it would be good if you perfected the method from your end since I'm not really experienced in the thing

addlistener commented 1 year ago

Do you think we need to mention fs.watchFile is actually polling the file and has a default interval of 5007ms? Cost me another 20min to figure this out lol.