1
Files don't update in editor after writing?
DuyNguyen27 (0)

I'm using Nodejs, and I'm doing a bit of reading/writing to files using fs.writeFileSync and fs.readFileSync.

Writing a file the first time is fine. Writing it the second time, the file in the editor doesn't update. It contains the old data. However, reading it back in using Nodejs, the contents of the file are as expected.

Is there a way to force the editor to display the file properly?


Here's a snip of what I'm talking about

var fs = require('fs');
function update() {
  var myContent = "This text was written at " + (new Date().toGMTString());
  fs.writeFileSync('helloworld.txt', myContent);

  console.log(fs.readFileSync("helloworld.txt").toString());
}
setInterval(update, 5000);

The code will read and output the correct results every 5 seconds, but the file in the editor won't update. This causes some major problems with data integrity. I'm trying to store an accurate log of events, and that doesn't appear to be possible on repl.it.

https://repl.it/@DuyNguyen27/Test

You are viewing a single comment. View All
Answered by eankeen (529) [earned 5 cycles]
View Answer
1
a5rocks (502)

So programmatic file writing is wonky in repl...

Try becoming an explorer, or just host your logs somewhere else (I recommend MongoDB Atlas).

But if you press "stop" all the edits should happen. However, if you don't stop your repl and it shutsdown after a while I don't think it saves.

https://repl.it/site/docs/repls/files#file-changes