javascript - How to check if file exist before appending data into it using nodejs? -


i have case once user download file deleting directory, once new message comes in still trying append file not exist , how can check if obj.file exist append ?

server.js

recordlogs: function (obj) {     var path = './app/records/templogs'     var fileappend = path + '/'+ obj.file;     console.log('data 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);             }         });     }); } 


Comments