Way to run React development server in a background

Viewed 2358

I would like to ask if there is any way to run the React app in development mode as a background process so it won't hog the terminal. I study computer science and I use SSH to connect to the school PC. It is the way my teacher requires it. As my project, I chose to react app, and sadly I have trouble using the terminal when my app is running. Is there any way to run "npm run start" as I background process so I could still use the terminal as normal and maybe kill the process later??

What I tried: Using & in command (didn't work, threw an error), pm2, nohup command

Thanks a lot

5 Answers

Using pm2 pm2 start "npm start" --name my_react_app

It depends on what kind of terminal you're using, but typically you can do cmd+T for mac or ctrl+T for windows to open a new terminal tab. This way you can do multiple things at once in the same terminal. Hope this helps!

  1. npm run start & - It will run at background but print all information on the screen, you can press Ctrl+L to clean the screen then to other jobs.
  2. npm run start > /dev/null & - Same as above but just will only print error information.
  3. npm run start > /dev/null 2>&1 & - This one will not print any information.

When you want to end it, you can use jobs -l to query it's PID then use kill + PID kill it, or use fg let it turn to front then press Ctrl+C to end process.

Another choice is use terminal multiplexer like Tmux/screen/Dvtm with learning cost.

Related