I was trying to build a generic function which will append to a file. Depending on the outcome the function will either return status of 200 or 500.
The initial set up should call the function and return either of statuses. After invoking the method, I am receiving an empty object.
The function is part of a class, and all required imports have added. I did try to return an fs.appendFile but I manage to receive the same result.
/**
* A functio which writes a data into a file
* @param {[string]} fileName A file location with file name string
* @param {[string]} msg A data to be saved
* @return {[object]} A response object with response code and msg.
*/
static toFile(fileName, msg) {
fs.appendFile(fileName, msg, function(err) {
let responseObject = {};
if (err) {
responseObject.status = 500;
responseObject.msg = 'Error occured please view ' + fileName;
return responseObject;
}
responseObject.status = 200;
responseObject.msg = 'Success, file has been created ' + fileName;
return responseObject;
});
}