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
Asked
Active
Viewed 747 times
0
-
3"In fact I'v tried too many codes but it didn't work properly" Care to share any of these attempts? – JDunken Mar 05 '20 at 21:25
-
you can work with file system only in Node.js – Mechanic Mar 05 '20 at 21:28
-
with nodeJS file-io https://www.npmjs.com/package/files-io – Mister Jojo Mar 05 '20 at 21:30
-
maybe this helpful : https://stackoverflow.com/questions/53446570/replace-a-line-in-txt-file-using-javascript – Mostafa Ahmed Mar 05 '20 at 21:48
1 Answers
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!');
});
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
-
Thank you so much but I'm trying to make a web app on my device only [without upload it to internet] is this methode suitable for my taget? – karam E Mar 07 '20 at 08:09
-
Does your app run in a web browser like Firefox, Chrome, or Internet Explorer? – Bastian Stein Mar 07 '20 at 10:02
-
-
-
By node.js but that is NOT satisfying enough so I decided to use PHP server with JavaScript Ajax. – karam E Mar 07 '20 at 19:46