Home > Blockchain >  How can I run rails server with yarn start?
How can I run rails server with yarn start?

Time:02-15

Is there a way for me to start my frontend on Reactjs when I start my server on Rails with a single command?

CodePudding user response:

Assuming you're current directory is your Rails project, you could make a script like this

#!/bin/bash
trap 'kill 0' INT
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).

CodePudding user response:

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.

  • Related