I'm making like a messageboard system and I'm already using those XMLHttpRequest things to obtain a JSON database, and I was wondering if it is possible to edit a file using those.
So far my file system looks like this
index.html (node.js + express server file)
public >
index.html
message.js (loads posts.json, parses the array, and adds them to the main posts section on the webpage)
posts.josn (small, database-like json file)
style.css
posts.json looks like this:
[
{
"user":"User",
"text":"Message 2"
},
{
"user":"User",
"text":"Message 1"
}
]
I would think an easy way to edit this is just to stringify the JSON that I already have from loading the posts, add a new post object thing, and then like send that out to replace the current data in the file.
(p.s. also I know this is probably a terrible way to set this up and I've used socket.io many times before and I probably should use that for serving the files and do that there but I'm too lazy at the moment and I'll probably do so later.)
Thanks!
question from:
https://stackoverflow.com/questions/65930575/how-to-edit-a-server-side-file-in-javascript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…