So I used fs.readFile() and it gives me
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of
memory
since fs.readFile() loads the whole file into memory before calling the callback, should I use fs.createReadStream() instead?
That's what I was doing previously with readFile:
fs.readFile('myfile.json', function (err1, data) {
if (err1) {
console.error(err1);
} else {
var myData = JSON.parse(data);
//Do some operation on myData here
}
}
Sorry, I'm kind of new to streaming; is the following the right way to do the same thing but with streaming?
var readStream = fs.createReadStream('myfile.json');
readStream.on('end', function () {
readStream.close();
var myData = JSON.parse(readStream);
//Do some operation on myData here
});
Thanks