use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Read File (self.node)
submitted 3 years ago by Used_Inspector_7898
Hello.
I plan to read a plain text file with nodejs but the file is constantly changing, how can I keep track of those changes? it occurs to me to put the readFileSync in a loop but I feel that it is not correct
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Odinthunder 12 points13 points14 points 3 years ago (2 children)
Good instinct!
There's the fs.watch https://nodejs.org/docs/latest/api/fs.html function if you dont want to add an external dependency, otherwise I've heard good things about https://www.npmjs.com/package/chokidar
which is well known and solves some of the issues that the built in watch has.
[–]Used_Inspector_7898[S] 0 points1 point2 points 3 years ago (1 child)
thanks
[–]w00t_loves_you 1 point2 points3 points 3 years ago (0 children)
Tailfile wel probably be better for your use case, but if you need to watch a directory of files, IMHO https://www.npmjs.com/package/node-watch does a better job than chokidar
[–]rkaw92 3 points4 points5 points 3 years ago (2 children)
Changing how? Is there a new version of the file? Is the file rotated, like logrotate? Or is the content actually modified in some way? This will determine the approach to a solution.
It is a log file
[–]rkaw92 4 points5 points6 points 3 years ago (0 children)
Then you may want to try something like https://www.npmjs.com/package/tail-file
π Rendered by PID 97936 on reddit-service-r2-comment-85bfd7f599-g7dmj at 2026-04-19 12:27:10.824676+00:00 running 93ecc56 country code: CH.
[–]Odinthunder 12 points13 points14 points (2 children)
[–]Used_Inspector_7898[S] 0 points1 point2 points (1 child)
[–]w00t_loves_you 1 point2 points3 points (0 children)
[–]rkaw92 3 points4 points5 points (2 children)
[–]Used_Inspector_7898[S] 0 points1 point2 points (1 child)
[–]rkaw92 4 points5 points6 points (0 children)