AdmiralCharl
AdmiralCharl

Reputation: 19

npm start in React

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

Upvotes: 1

Views: 972

Answers (3)

pritam
pritam

Reputation: 2558

You could use '&&' like:

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

Upvotes: 1

tomrlh
tomrlh

Reputation: 1066

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

Upvotes: 2

kenmistry
kenmistry

Reputation: 2143

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

{
  "dev": "concurrently \"npm run server\" \"npm start\""
}

Upvotes: 5

Related Questions