I have a Heroku app of the following structure:
I'm trying to write to data.csv whenever a specific function is called. Then, I run heroku run bash -a app_name (which I believe shows the app environment). In the bash, when I run 'cat data.csv', the file contents haven't been updated. I'm using the fs module to append to the file, but for some reason it's not working. Any help appreciated:
fs.stat('./data.csv', function (err, stat) {
if (err == null) {
console.log('File exists');
//write the actual data and end with newline
var csv = json2csv(jsonObject) + newLine;
fs.appendFile('./data.csv', csv, function (err) {
if (err) throw err;
console.log('The "data to append" was appended to file!');
});
} else {
//write the headers and newline
console.log('New file, just writing headers');
fields = fields + newLine;
fs.writeFile('./data.csv', fields, function (err) {
if (err) throw err;
console.log('file saved');
});
}
});
When I run the function, it prints "The "data to append" was appended to file!", so I know the function is running correctly, but either 1) I'm not accessing the correct file, 2) writes are not persisted after the function ends 3) something else.