Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda