Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs forever : How to run my npm application

Right now i am runnign my nodejs application as npm start. i want to run it in background. I found forever package for this but dont know how can i run a application that i usually run as npm start. So how can i run it using forever ?

I follow this SO but getting this error:

ENVIRONMENT=production forever start app.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: app.js

apart of this Is there any other better way to run nodejs in background ?

like image 574
Manish Kumar Avatar asked Dec 03 '14 14:12

Manish Kumar


2 Answers

You are doing it right.

The warnings are just reminding you that some essential information is missing, so it assigns the defaults. To be exact, if your script crashes/exits sooner than a second after start, forever will exit as well.


If you would like to get rid of those warnings:

forever start --minUptime 1000 --spinSleepTime 1000 app.js 

Furthermore, you can open the package.json file, find the:

  "scripts": {
    "start": "node app.js"
  },

and change it to:

  "scripts": {
    "start": "forever start --minUptime 1000 --spinSleepTime 1000 app.js",
    "stop":  "forever stop app.js"
  },

Now you can use npm start and it will invoke forever automatically.

like image 195
alandarev Avatar answered Nov 19 '22 15:11

alandarev


In 2022

Use forever npm package ( https://www.npmjs.com/package/forever )

forever start -c "npm <command\>" /path/to/app/dir/

EXAMPLE

./ means current directory

forever start -c "npm start" ./
like image 12
Nisharg Shah Avatar answered Nov 19 '22 13:11

Nisharg Shah