Node.js: Count the number of lines in a file

前端 未结 10 680
一向
一向 2020-12-02 23:02

I have large text files, which range between 30MB and 10GB. How can I count the number of lines in a file using Node.js?

I hav

10条回答
  •  没有蜡笔的小新
    2020-12-02 23:45

    You can also use indexOf():

    var index = -1;
    var count = 0;
    while ((index = chunk.indexOf(10, index + 1)) > -1) count++;
    

提交回复
热议问题