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

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

    Here is another way without so much nesting.

    var fs = require('fs');
    filePath = process.argv[2];
    fileBuffer =  fs.readFileSync(filePath);
    to_string = fileBuffer.toString();
    split_lines = to_string.split("\n");
    console.log(split_lines.length-1);
    

提交回复
热议问题