导航栏: 首页 评论列表

process out of memory nodejs 一行 一行 读取文件

默认分类 2013/10/15 22:56

nodejs - 读取大文件的时候 content=readFileSync(..).toString()报错。

FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory

解决办法:一行一行读取文件,地址 https://github.com/nickewing/line-reader

安装npm

npm install line-reader

示例代码:

var lineReader = require('line-reader');

lineReader.eachLine('file.txt', function(line, last) {
  console.log(line);

  if (/* done */) {
    return false; // stop reading
  }
});

Shell

>> nohup node app.js >> log.dat 2>&1 &


>> 留言评论