-3

I need to write a js function to write the form information into a .txt

i will not use database in this project, i will use .txt files to control everything, products, person, employee , etc. All they will be at a .txt called control.txt with the information like this:

[person]name|email|date

[employee]name|department

So i need a function that writes the form information into my .txt archive.

2 Answers2

0

You can't.

Think this through for a minute, you want javascript code on a users computer to be able to directly edit a file on your webserver.

The security risks of allowing writing to arbitrary files on a server would be insane. Not to mention handling conflicts with multiple clients.

There is a reason why databases are used. If you want to modify data on a server you need some kind of server side layer.

lod
  • 1,098
  • 10
  • 13
0

While I don't really recommend doing this through text file. You may find filesaver.js useful in manipulating text file https://github.com/eligrey/FileSaver.js.

However as @lod pointed out, you can't really edit the text files of user directly. That's why there are fakepath whenever we put a file in a file upload component

Your best bet is to save the text file in server and read it from there. Once you are done editing/creating the text. upload it back in the server.

But this sounds more tedious rather than creating a simple database service imho

keysl
  • 2,127
  • 1
  • 12
  • 16