My project sturture is as follows :
Projects --- package.json
|-------Project1 ---- package.json
|-------Project2 ---- package.json
if I run yarn start
from cd Projects/Project1
, project1 react app runs.
if I run yarn start
from cd Projects/Project2
, project2 react app runs.
for running the app from Projects, I need to specify project name : eg: yarn start-Project1
I want to run both my projects from the top most directory using yarn start. I want to run the projects on different ports.
If I change the package.json
in "Projects" to this
"start": "cd Projects/Project1 && export PORT=3001 && cd ../Project2 && export PORT=3000 && react-scripts start",
It is only running of the project. Thank you.
This is because the &&
operator runs commands in sequence, meaning each command runs after the previous command exits. Your Project1 doesn't exit, it just sits there running indefinitely.
You need to run both your commands in parallel. One way to do this is to use &
instead of &&
. &
will start the first command in the background instead of waiting for it to exit.
When using &
you should be careful of the order of operations. You can use parentheses to group sequential/parallel commands as necessary. I think this command might work for you:
(cd Projects/Project1 && export PORT=3001) & (cd ../Project2 && export PORT=3000) & react-scripts start