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

前端 未结 10 681
一向
一向 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:47

    var fs=require('fs');
    filename=process.argv[2];
    var data=fs.readFileSync(filename);
    var res=data.toString().split('\n').length;
    console.log(res-1);`
    

提交回复
热议问题