I have a case where once user download a file i am deleting it from the directory, Now once new message comes in its still trying to append to the file that does not exist , How can i check if obj.file exist then only append ?
server.js
recordLogs: function (obj) {
var path = './app/records/templogs'
var fileAppend = path + '/'+ obj.file;
console.log('data from recoring', obj.data);
fs.readdir(path, function(err, items) {
items.forEach(function(file){
if(obj.file === file){
fs.appendFile(fileAppend, obj.data, null, 'utf8', function (err) {
if (err) throw err;
});
console.log('filename in records',obj.file);
}
});
});
}