Reputation: 919
I'm going to run react-boilerplate application forever in the server. I found forever and I'm not sure how I pass parameters to forever. The command to run server is like following:
PORT=80 npm run start:production
Seems like forever start PORT=80 npm run start:production
doesn't help me.
Upvotes: 8
Views: 9927
Reputation: 819
For this you will need:
npm install -g forever
PORT=<YOUR PORT> forever start -c "<command>" ./
Your command can be for example npm start
and npm run dev
.
Use ./
only if you are in the project folder.
Port means your port number, usually 80
or 443
.
Upvotes: 0
Reputation: 457
pm2 is superb production process manager for Node. In addition to starting and daemonizing any application, it has a built in load balancer.
Install pm2:
npm install pm2 -g
To add start and add deamon to your app, navigate to the app folder and:
pm2 start app.js
To make pm2 autoboot on server restart:
$ pm2 startup
Then copy and paste the code generated.
Upvotes: 0
Reputation: 6568
Or you can run a react application with pm2 or with nohup
1) install pm2 globally
npm install pm2 -g
2) navigate to the project folder and execute, space is required after --
pm2 start npm -- start
3) to see running instances
pm2 ps
4) to see the other options
pm2 --help
To run with nohup
1) navigate to the project folder
nohup bash -c 'npm start' &
Upvotes: 5
Reputation: 3873
One thing is that PORT=80
part is setting the env variable, this kind of command should be in front of other commands. The other thing is that to run npm scripts with forever, you need to use different syntax, so PORT=80 forever start -c "npm run start:production" /path/to/app/dir/
.
If you're running forever form the project folder, the path should be ./
Upvotes: 5