when i am writing recursive program which reads 70mb file line by line and processes.I am using recursion to process the line .here is my code
function readFile(response, postData){
var instream = fs.createReadStream('filePath');
var datmap={};
var rl = readline.createInterface({
input: instream,
output: outstream,
terminal: false
});
rl.on('line', function(line) {
hirarchyFun(datmap,line);
});
}
hirarchyFun=function(map,line){
var key;
if(line.indexOf(",") != -1){
key=line.substring(0,line.indexOf(","));
var subLine=line.substring((key.length+1));
var internMap=map[key];
if(typeof internMap == 'undefined'){
internMap={};
}
var value=hirarchyFun(internMap,subLine);
map[key]=value;
return map;
}else{
return line;
}
}
when I am reading file which is about 70mb giving error as
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
but its working fine for file about 700kb. can any one help on this issue??