5

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.

Smart Solutions
  • 741
  • 1
  • 7
  • 25

5 Answers5

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

Gleb Kostyunin
  • 2,923
  • 1
  • 16
  • 33
2

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' &
NuOne
  • 4,218
  • 1
  • 27
  • 39
1

you can run react process as background process using forever

forever takes a command and run it in background. the default forever command is node, so when you run forever start , it will execute forever start -c "node"

-c option is for command to run in background.

in case of react app you can go to the root directory of your react application and then execute the following command:

forever start -c "npm start" ./

you can see a list of background processes that use forever as follow:

forever list

Ali_Hr
  • 2,286
  • 2
  • 17
  • 27
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.

Kevin Ogoro
  • 89
  • 1
  • 5
0

Step 01: npm intsall -g forever

Then, run PORT=<YOUR PORT> forever start -c "<command>" ./

  1. commands ex: "npm start" , "npm run dev" according to your requirement.
  2. Note: ./ means you are in the project folder
  3. PORT=Your port number