0

In fact I'v tried too many codes but it didn't work properly. I want A javascript code to replace the content of TXT file. All codes I got were for updating the content with the old data. Thanks

karam E
  • 25
  • 5

1 Answers1

0

You can replace the contents of a file in node.js like so:

const fs = require('fs');

fs.writeFile("message.txt", "new content", (err) => {
    if (err) throw err;
    console.log('The file has been saved!');
}); 

docs

It's not possible for code running in a browser, as this would constitute a major security risk.

Bastian Stein
  • 2,147
  • 1
  • 13
  • 28