How to do `tail -f logfile.txt`-like processing in node.js?

后端 未结 5 2227
遇见更好的自我
遇见更好的自我 2020-12-24 01:19

tail -f logfile.txt outputs the last 10 lines of logfile.txt, and then continues to output appended data as the file grows.

What\'s the recommended way

5条回答
  •  甜味超标
    2020-12-24 02:17

    node.js APi documentation on fs.watchFile states:

    Stability: 2 - Unstable. Use fs.watch instead, if available.

    Funny though that it says almost the exact same thing for fs.watch:

    Stability: 2 - Unstable. Not available on all platforms.

    In any case, I went ahead and did yet another small webapp, TailGate, that will tail your files using the fs.watch variant.

    Feel free to check it out here: TailGate on github.

提交回复
热议问题