Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
File in Heroku app not being appended to?

I have a Heroku app of the following structure:

  • APP
    • app.js
    • package.json
    • package-lock.json
    • Procfile
    • node_modules
    • data.csv

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!