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

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

    You could do this as the comments suggest using wc

    var exec = require('child_process').exec;
    
    exec('wc /path/to/file', function (error, results) {
        console.log(results);
    });
    

提交回复
热议问题