Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can reactJS write into file?

Tags:

reactjs

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.

like image 780
Kirdeika Avatar asked Mar 26 '18 12:03

Kirdeika


People also ask

Can we write HTML in React?

JSX allows us to write HTML in React. JSX makes it easier to write and add HTML in React.

How do I send a file using react JS?

In order to upload files, the 'content-type' header must be set to 'multipart/form-data'. new FormData() creates a new empty formData object that we send as the payload in our POST request. Our POST request assumes there is an API endpoint on our backend server at http://localhost:3000/uploadFile. We're done!


2 Answers

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.

like image 94
Huy Nguyen Avatar answered Oct 19 '22 21:10

Huy Nguyen


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.

like image 16
Stretch0 Avatar answered Oct 19 '22 19:10

Stretch0