DEV Community

Radheshyam Gupta
Radheshyam Gupta

Posted on

fs.writeSync

can i use fs.writeSync in react app,
please help me regarding this issue.

Thanks

Top comments (12)

Collapse
 
khokon profile image
Khokon M.

React is a client side application, and client side application can't access file system.

Collapse
 
radhe65gupta profile image
Radheshyam Gupta

Please,can you help me regarding this?,

Collapse
 
emmiep profile image
Emmie Päivärinta

What exactly do you want to accomplish?

Thread Thread
 
radhe65gupta profile image
Radheshyam Gupta

i want to create react app and i use fs.writeSync

Thread Thread
 
emmiep profile image
Emmie Päivärinta

Yes, but what kind of file do you want to write, and why? Maybe writeSync isn't the solution.

Thread Thread
 
radhe65gupta profile image
Radheshyam Gupta

i want to save data in the form of json file in local

Thread Thread
 
emmiep profile image
Emmie Päivärinta

Ok. Like @khokon said, for that you'd need a server. Do you already run your React app on a local server?
Personally, I usually go for something like Next.js instead, which lets you use serverless API functions, it makes it very easy to add some nodejs "glue code" to a react project.
Storing files might not be a great fit for that, if it's possible I would recommend saving your JSON data on a server instead. It's very easy to get started with for instance Redis with a library like node-redis or ioredis in Next.js, and with a service like Upstash you can do that for free.
There are more solutions for databases specifically targeting serverless available for free or very cheap, like MongoDB or CockroachDB.
I suggest you take a look at some databases first, in the end it might be a lot easier to deploy. I hope this helped!

Thread Thread
 
radhe65gupta profile image
Radheshyam Gupta

thanks Emmie Paivarinta

Collapse
 
khokon profile image
Khokon M.

You need to have a backend running using nodejs. Only then you can use the function

Thread Thread
 
radhe65gupta profile image
Radheshyam Gupta

can u share any reference?

Collapse
 
radhe65gupta profile image
Radheshyam Gupta

hello

Collapse
 
zabdeldjallil profile image
Djilou

Option 1:You can make a node js file in your react project then run a node ./nodescript.js in your hosting server.
Option 2: make a small node js server that you will send a request to from your react app (using fetch or axios)