0

As my first batch script, I want to run my backend and frontend with just one script. My backend is in python with Django and my frontend is in react. I, therefore, have to processes I need to run. But I don't know how to run them in parallel as I need to start a virtual environment in python first.

I don't understand how it would log the server logs. Is there an option to make two terminal windows or a new terminal tab? Or would it log in to one terminal together?

#!/bin/bash

DJANGODIR=/Users/usr/Desktop/programming/app/django
REACTDIR=/Users/urs/Desktop/programming/app/react

# START REACT FRONTEND
echo Starting React Server
# Option 1
# cd $REACTDIR
# npm start

# Option 2
# start app from any directory without cd into it
# npm --prefix $REACTDIR run start


# START DJANGO BACKEND
echo Starting Django Server
# cd $DJANGODIR

# Start virtual environment
# source venv/bin/activate

# Start Server
# python3 manage.py runserver

# Activating and running in one command
# source venv/bin/activate python3 manage.py runserver


# Here is where I'm not knowing how to run them in parallel
source venv/bin/activate python3 manage.py runserver & npm --prefix $REACTDIR run start
BenjaminK
  • 653
  • 1
  • 9
  • 26

1 Answers1

0

Have you tried with the pipe operator? Pipe operator explained

root
  • 164
  • 11
  • I just have. But using the `|` with `source venv/bin/activate python3 manage.py runserver | npm --prefix $REACTDIR run start` seems to kill the first process during starting and overwrites it with the second similar to using the `&` – BenjaminK Aug 05 '22 at 06:11