How to run React Boilerplate with forever
Asked Answered
L

4

8

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.

Lynden answered 5/3, 2018 at 4:37 Comment(0)
F
5

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 ./

Fran answered 5/3, 2018 at 13:45 Comment(0)
I
5

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' &
Ingathering answered 29/4, 2019 at 10:55 Comment(0)
T
0

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.

Tonnage answered 8/7, 2019 at 8:57 Comment(0)
G
0

For this you will need:

  1. Install forever usingnpm install -g forever
  2. Run the forever command 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.

Giroux answered 22/2, 2021 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.