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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With