1

how can I start both this only by typing npm start?

"scripts"{
    "server": "json-server --watch appointmentList.json",
    "start": "react-scripts start",
}

what i've been doing was running each of them in different terminal

Synapsido
  • 136
  • 3
  • 12
  • Does this answer your question? [How can I run multiple npm scripts in parallel?](https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel) – Emile Bergeron Dec 10 '19 at 01:57

3 Answers3

5

you can install concurrently to run the scripts in parallel, like this:

{
  "dev": "concurrently \"npm run server\" \"npm start\""
}
kenmistry
  • 1,728
  • 1
  • 13
  • 23
2

In short, you can append the desired commands to the start script:

"scripts": { 
    "server": "json-server --watch appointmentList.json", 
    "start": "json-server --watch appointmentList.json && react-scripts start"
}

and call it with $npm run start or $npm start

tomrlh
  • 976
  • 1
  • 15
  • 36
1

You could use '&&' like:

{
    "server": "json-server --watch appointmentList.json", 
    "start": "npm run server && react-scripts start"
}
pritam
  • 2,247
  • 1
  • 19
  • 28
  • i tried this before but its not working. my server server runs in 3000, and my react app runs at 3001. so Im doing it on different terminal – AdmiralCharl Dec 15 '19 at 19:38