Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running React while rebooting Ubuntu server

Tags:

reactjs

ubuntu

Whenever I run the React app, I have to run manually by typing yarn build & yarn start. If I reboot the server, I should re-run manually again. Is there a better way of automatically running the web engine?

My idea is writing the command in /etc/rc.local file. But I am not sure if this is proper or not.

Thank you.

like image 884
user19881219 Avatar asked Nov 27 '25 18:11

user19881219


1 Answers

Use pm2: Advanced, production process manager for Node.js.

First install pm2 with

npm install --global pm2

and then you can start your app by

cd /path/to/app
pm2 start npm -- start

The pm2 will manage your React service.

If you want to auto run this on boot:

pm2 save        # Save your process.
pm2 startup     # Install auto start script.

Further information, you can find pm2 docs here.

like image 73
NoobTW Avatar answered Nov 29 '25 13:11

NoobTW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!