i am trying to fetch data from the db.json.
here is my db.json file:
{
"posts": [
{ "id": "react-hooks", "title": "React Hooks", "content": "The greatest thing since sliced bread!", "author": "ali" },
{ "id": "react-fragments", "title": "Using React Fragments", "content": "Keeping the DOM tree clean!", "author": "ali" }
],
"users": [
{ "id": 1, "username": "ali", "password": "********" }
],
"themes": [
{ "id": 1, "primaryColor": "deepskyblue", "secondaryColor": "coral" },
{ "id": 2, "primaryColor": "orchid", "secondaryColor": "mediumseagreen" },
{ "id": 3, "primaryColor": "darkslategray", "secondaryColor": "slategray" }
]
}
after that i have executed > npm install --save json-server and > npx json-server --watch server/db.json and i have edited the "scripts": part as followed:
"start:server": "npx json-server --watch server/db.json",
"start:client": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
then i have excuted > npm install --save concurrently and then i have added that line in the "scripts":
"start": "npx concurrently \"npm run start:server\" \"npm run start:client\"",
then i have executed > npm install --save http-proxy-middleware and after that i have created setupProxy.js and put the following code:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports=function(app){
app.use(createProxyMiddleware('/api',{
target:'http://localhost:5000',
pathRewrite:{'^/api':''}
}))
}
then i excuted npm install and after that when i execute npm start it shows the following error:
The system cannot find the file :client.
[5] start:client exited with code 1
[2] The system cannot find the file :server.
[2] start:server exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reacttutorial@0.1.0 start: `npx concurrently "npm run start:server" "npm run start:client"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reacttutorial@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
and there are two windows alerts which are saying that ':server' and ':client' cannot be found.
i have created whole new app by executing npx create-react-app reacttutorial. i am just running out of ideas. can anyone help me on that please?