Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start React JS application in background mode on linux?

Tags:

reactjs

I am new to ReactJS, I want to start my react application in background mode or in detach mode. In Ruby On Rails -d option is available to start application in background mode. How should I do this in ReactJS application.

I tried running npm run build, it generated the optimised production build. Please suggest.

like image 693
Chetan Tete Avatar asked Dec 01 '22 10:12

Chetan Tete


2 Answers

Take a look on pm2 this should be exactly what you want.

To install pm2 :

npm install pm2 -g

To start an application simply just run :

pm2 start npm -- start

You can check logs via:

pm2 logs

To stop current pm2 instances

1) list the pm2 processes, get the id, lets say the id is 0

pm2 ps

2) then stop the id

pm2 stop 0
like image 163
MaddEye Avatar answered Dec 04 '22 00:12

MaddEye


You can build the project by npm run build if you have your build script defined in your package.json and then serve the build folder with serve first install serve

npm install serve -g 

then run serve

serve -s build -l port_number

if you want this to run in background and maintain the log, redirect the standard out and error out to a file, execute following

serve -s build -l port_number &> filename.log &

if you just want to run serve it in background

serve -s build -l port_number &

You can use nohup as well

nohup bash -c 'npm start' &

& for background processing

like image 31
NuOne Avatar answered Dec 04 '22 00:12

NuOne