Is there a way for me to start my frontend on Reactjs when I start my server on Rails with a single command?
Asked
Active
Viewed 340 times
3 Answers
1
You could make a script like this
#!/bin/bash
trap 'kill 0' INT
cd [path-to-rails-project] && rails s &
cd [path-to-react-project] && yarn start &
wait
This script should run both servers, and stop both servers when an interrupt is triggered (ctrl-c).

Cameron
- 756
- 6
- 16
-
Thanks for your answer! Do you mean making a script file and typing bash command? I don't preffer to make the file to root directory. Can I use that script as alias or something? – Hinoarashi Feb 15 '22 at 05:03
-
Yes, you would save this script to a file and execute it as a bash command. I modified the script so that you can store it anywhere in your filesystem. – Cameron Feb 15 '22 at 17:04
-
Thank you! I got it using alias. – Hinoarashi Feb 16 '22 at 14:00
1
You can use https://www.npmjs.com/package/concurrently package to achieve that, adding to you'r package something like:
"start": "concurrently \"bin/webpack-dev-server\" \"bin/rails s\""

crsde
- 162
- 11
0
You could create a Makefile or a command-line alias that chains them together (e.g. alias startall="rails s; yarn start"
). If they're in different directories it may be a bit more complicated, but you can specify a path with yarn. Also worth noting the difference between &&
and ;
in Bash which you can read about here.

Blake Gearin
- 175
- 1
- 10