Run Backend and Frontend with a Single Command
I’ve been thinking about how I run my projects.
I’ve always done it like this: I run the backend and the frontend in two tabs in the system terminal (Bash or zsh). I know there are Git shortcuts in VS Code, but I like to use Git commands in the VS Code terminal, so I don’t run the projects there.
With that in mind, it’s a bit annoying to go into the folders in two tabs and run both, so I looked for solutions. I found npm-run-all and concurrently, but I don’t like installing extra tools just to do simple things, so I thought about using an alias to run both with a single command.
In the terminal, run the following command:
nano ~/.bashrc
This will open the bashrc file. At its last line, add the following (replacing the path and the command according to your project):
alias run-project="(cd project/backend && npm run dev) & (cd project/frontend && npm run dev)"
Press Ctrl+O to save the file and Ctrl+X to exit. Then, run the command below in the terminal to reload the terminal configuration file without having to close and reopen the terminal:
source ~/.bashrc
Now just run the command below in the terminal, and it will start both your backend and frontend at the same time.
run-project
Thank you for reading this article! Share your thoughts about it — knowledge is always welcome!