I wanted to know if there was a way to catch this error:
FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory
I have tried:
process.on('uncaughtException', function(err){
//do something
})
But this did not catch the error.
Any help would be greatly appreciated
P.S This is happening when generating MD5 hashes for a string of about eighteen files and I am using the md5 module like this:
for(i=0;i<array.length;i++){
fs.readFile(array[i], function(err,buf){
console.log(mdf(buf))
})
}
You should avoid buffering entire files in memory. Calculate the md5 hash a chunk at a time instead. Example:
var fs = require('fs'),
crypto = require('crypto');
var array = [ 'foo.txt' ];
array.forEach(function(filename) {
var hasher = crypto.createHash('md5', { encoding: 'hex' });
fs.createReadStream(filename).pipe(hasher).on('finish', function() {
process.nextTick(function() {
var md5sum = hasher.read();
console.log(filename + ': ' + md5sum);
});
});
});