Node.js read and write file lines

前端 未结 3 1269
甜味超标
甜味超标 2020-12-13 03:10

I tried to read a file line by line, and output it to another file, using Node.js.

My problem is the sequence of lines sometimes messed up due to async nature of Nod

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 03:53

    Why do not you use node.js plugin for the same: https://github.com/pvorb/node-read-files

    Installation: npm install read-files

    Usage:

      var fs = require("fs");
          require("read-files");
    
      fs.readFiles([ "file1", "file2" ], "utf8", function(err, data) {
          if (err) throw err;
    
          console.log(data);
      });
    

提交回复
热议问题