Skip to content

write huge data into a file in crashes node #2502

@ask-khan

Description

@ask-khan

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
});
});`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions