14

As my title says, is it possible? I am begginer at front-end and trying to teach myself reactJS right now. I learned some javascript before and I know it is impossible to read or write files with it. Mainly what I want to do is to get string from input and lets say write it into file.

Kirdeika
  • 237
  • 2
  • 3
  • 12
  • Looks like it's already asked and answered here: https://stackoverflow.com/questions/36569068/reactjs-how-to-read-and-write-to-a-file – Steffen L. Mar 26 '18 at 12:44
  • Yes, but in the link you provided person asks if he can read from file. My question (sorry if I was unclear) was that I want to add text into file from client side (for example: person types in his name and it will save into a file and its gonna be displayed on website permanently until removed manually from the file) – Kirdeika Mar 26 '18 at 12:57

2 Answers2

20

Well the question is, where does that file live?

Node is able to write to files because the files exist on the server that node is running on.

React runs in browser so there is no shared file system to write to. You can read from a file because the contents of that file get bundled into the Javascript that gets served to the browser.

If you want to write to a file, you would need to send an API request from your browser / React to a server and have that server write to the file system.

Additionally, as pointed out by Huy Nguyen, it's possible to write to the clients file system from the browser but that is going to be private to that user.

Stretch0
  • 8,362
  • 13
  • 71
  • 133
7

Your question is a bit vague. In addition to what @Stretch0 said, it's possible to read/write files on a user's computer using the browser's native APIs. Here is a good tutorial.

Huy Nguyen
  • 2,840
  • 1
  • 14
  • 18