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

后端 未结 5 2228
遇见更好的自我
遇见更好的自我 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:14

    Substack has a file slice module that behaves exactly like tail -f, slice-file can stream updates after the initial slice of 10 lines.

    var sf = require('slice-file');
    
    var xs = sf('/var/log/mylogfile.txt');
    xs.follow(-10).pipe(process.stdout);
    

    Source: https://github.com/substack/slice-file#follow

提交回复
热议问题