node.jsherokuheroku-cliheroku-api

Heroku view files changed by client


I made a simple Node.js server and deployed it to Heroku that serves a dead simple HTML form that returns submitted value to

fs.writeFile('./users.json',JSON.stringify(dataArr,null,4),(err)=>{
    if(err){console.log(err);}
    console.log('file saved');
  });

In Heroku's logs I can see "new file written" but I can't find a way to retrieve the saved information from the users.json file. When I try to do a pull request from Heroku, it says that everything is already up to date, even though in Heroku logs I can see "new file written".

How can I see the change in my users.json file?


Solution

  • You should be able to open it from your JavaScript code like any other file, but there's a huge catch: Heroku's filesystem is ephemeral. Any changes you make to it will be lost when your dyno restarts, which happens frequently.

    If you need to store data for any meaningful amount of time you'll have to put it elsewhere. Heroku recommends using something like Amazon S3 for file storage, or you could use a client-server database like PostgreSQL.

    Based on its filename I'd guess a database is a better option here, though of course without knowing what users.json actually contains and how it's used I can't say for sure.