-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Description
The node crashes when writing around ~600MB of data into a file. It works fine if the writable data is smaller.
P.S. My server has 4 GB of ram.
How to solve this issue? Any help would be highly appreciated. The code is list below I am using write function of fs and I can used pipe for it but for this i have to readstream function in it with writestream
`function logIntoFile (logObject){
let date = new Date();
let currentDate = date.getFullYear() + '-' + (((date.getMonth() + 1) < 10) ? '0' : '') + (date.getMonth() + 1) + '-' + ((date.getDate() < 10) ? '0' : '') + date.getDate();
let currentHour = ( (date.getHours() < 10 ? '0' : '') + date.getHours() );
let fileName = '/custom-logs/resultSet_' + currentDate + '_' + currentHour + '@' + logObject.dbName;
let logFile = fs.createWriteStream(__dirname + fileName, { flags: 'a' });
logFile.write(util.inspect(logObject, false, null) + '\n');
logFile.end();
}
// doQuery contains logic to connect to DB and run the query provided
doQuery(req, res, sql, false, function(err, result){
if (err) {
...
console.error(err);
res.send(err);
} else {
...
res.send(result);
...
logIntoFile({
timeStamp : getCurrentDateTime(),
dbName : req.session.iss.dbname,
userId : inuserid,
sql : sql,
error : err,
response : result
});
});`