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.
JSX allows us to write HTML in React. JSX makes it easier to write and add HTML in React.
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!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With