20

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 ?

1
  • 5
    i don't see an error, just warnings....? Commented Dec 3, 2014 at 14:20

3 Answers 3

30

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.

Sign up to request clarification or add additional context in comments.

1 Comment

For anyone seeing this who's using express-generator and starts their application using "npm start", replace "app.js" with "`pwd`/bin/www"
17

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

Comments

-1

For Linux Use terminal and enter in superuser mode, and try these code

$ nohup node <location of of js file> &
$ exit

Note: This '&' is must before you press enter

or for npm command, just goto the location by cd command where your package.json is stored. Then

$ nohup npm start &
$ exit

Note: This '&' is must before you press enter

To stop it

$ top

You can see process id here, then use following code

$ kill -9 <PROCESS_ID>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.