imkeVr
imkeVr

Reputation: 472

React command on yarn start and also init server with same command

I'm trying to attach another command to yarn start. I'm not sure if it is possible but when I run command yarn start I want my react app to start and I also want to fire up my server at the same time.

What I do know is use 2 terminals one with react app directory and call on yarn start

C:\Users\ivanr\Documents\GitHub\bees\business-scheduler>

and one with server directory (which is inside react app directory) and call on node src/index.js

C:\Users\ivanr\Documents\GitHub\bees\business-scheduler\server>
  "scripts": {
    "start": "react-scripts start", // is it possible that I can say in server directory run node src/index.js here?
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Upvotes: 1

Views: 1855

Answers (2)

Rahul Chandwani
Rahul Chandwani

Reputation: 61

You can use npm-run-all

"scripts": {
    "clean": "rimraf dist",
    "lint":  "eslint src",
    "build": "babel src -o lib"
}

npm-run-all clean lint build

Upvotes: 0

gzcz
gzcz

Reputation: 526

You can use concurrently

First install it

$ npm install concurrently

Then use it in your command

"scripts": {
  "start": "concurrently \"yarn start-client\" \"yarn start-server\"",
  "start-client": "react-scripts start",
  "start-server": "cd .\server && node src/index.js"
}

Upvotes: 4

Related Questions