Read a file one line at a time in node.js?

前端 未结 29 1632
深忆病人
深忆病人 2020-11-22 04:33

I am trying to read a large file one line at a time. I found a question on Quora that dealt with the subject but I\'m missing some connections to make the whole thing fit to

29条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 05:08

    In most cases this should be enough:

    const fs = require("fs")
    
    fs.readFile('./file', 'utf-8', (err, file) => {
      const lines = file.split('\n')
    
      for (let line of lines)
        console.log(line)
    });
    

提交回复
热议问题