Reputation: 4918
I have my package.json start like this
"scripts": {
"start": "react-scripts start",
How to add also “json-server db.json” to start ?
Upvotes: 0
Views: 176
Reputation: 4918
This combination worked with me. I had to choose another port + run as parallel.
"start": "run-p jserver rscript",
"rscript": "react-scripts start",
"jserver": "json-server db.json --port 3004",
Upvotes: 0
Reputation: 20755
You can simply do this,
"scripts": {
"start": "react-scripts start && json-server --watch db.json",
}
Note: You must install your json-server
globally like npm install -g json-server
.
Also make sure your db.json
file don't have any error / typo, because when json-server
it compiling the db.json
file and if any type mistake in db.json
file it show the error like
Error Showing: ERR! code ELIFECYCLE
Error Showing: ERR! errno 1
Upvotes: 0
Reputation: 6705
One more solution to use Concurrently (https://www.npmjs.com/package/concurrently)
npm install concurrently --save
"scripts": {
"start": "concurrently \"npm run server\" \"react-scripts start\"",
"server": "nodemon server/app",
"build": "react-scripts build",
...
Upvotes: 0
Reputation: 1416
You can use the npm-run-all module to be able to run multiple tasks.
"scripts": {
"start": "run-s rscript jserver",
"rscript": "react-scripts start",
"jserver": "json-server db.json"
}
Upvotes: 1