Is it not possible to store data to JSON file ? I mean I want to store the questions from the UI. I haven’t started my database concepts yet. I know it is far far efficient to use Database.
Can anyone tell me if it is not at all possible.
Thank you
I just now studied how to get data and it worked. But when i tried to search for storing data I wasn’t getting any results
2
Answers
In a React.js application, you can store data in a JSON file. You can read the JSON file using the
fetch
API or any other method, parse its contents, and then use the data within your React components.Here’s an example of how you can read data from a JSON file in a React component:
Also I recommend using json-server (https://www.npmjs.com/package/json-server )
Check it out
You can make a data.json with data for each api and run that json file in a server using command called npm run json:server
Add in package.json under scripts
"json:server":"json-server –watch –port "
Then run npm run json:server server will run
After that you can call the data such as calling to API sample API will be http://localhost/getNames
You can add more data and run again too