29

I am trying to run node server using forever command. I installed forever globally using:

npm install forever -g

After installing forever I try to run my node script by using below command:

node_modules\.bin\forever start app.js

Below is my console:

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up f
or at least 1000ms
info:    Forever processing file: app.js

Please help me to resolve this issue!

S Singh
  • 1,403
  • 9
  • 31
  • 47

9 Answers9

7

There is no problem here other than warnings for configs forever recommends you declare. If you see the final message there it tells you it has processed your script. Just run forever list and you should see your script running.

I ran into this same thing when installing npm via yum repository ( yum install npm ) and then installing forever whereas when I install node and npm via shell scripts and then install forever it doesn't occur. It must have something to do with the formulas for the package installer or potentially missing alias with flags with installer to set those values behind the scene.

Those don't mean it's not working. See below I created a js file using sample code from node's site and ran it manually (I flushed firewall to open port for app temporarily but you don't need that):

[root@app1 ~]# vi example.js
[root@app1 ~]# apf -f
apf(23924): {glob} flushing & zeroing chain policies
apf(23924): {glob} firewall offline
[root@app1 ~]# node example.js 
Server running at http://127.0.0.1:1337/

I then start app using forever:

^C[root@app1 ~]# forever start example.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: example.js

Now I check to see if my app is running:

[root@app1 ~]# forever list
info:    Forever processes running
data:        uid  command       script     forever pid   logfile                 uptime       
data:    [0] dan1 /usr/bin/node example.js 23976   23978 /root/.forever/dan1.log 0:0:0:27.320 
[root@app1 ~]#
Mike S.
  • 4,806
  • 1
  • 33
  • 35
  • 1
    The part I was missing was the fact the message `Forever processing file: app.js` means that it worked. I didn't realize that the file was processed in the background and you had to do `forever list` to see the processes. I now have 4 running because I tried this over and over again. Haha. – kentcdodds Dec 21 '13 at 14:06
  • 1
    But the changes are not reflecting when i refresh my web page after making some changes in the back end code in app.js – Ankur Marwaha Aug 16 '16 at 16:18
4

This solved my issue:

forever start -c node [path/to/app]

"-c" means - Run commnad; and then just run via nodejs

This way - you get the Respawn by default of min. 1000ms uptime

Taken from: https://github.com/nodejitsu/forever/issues/422, by "Basarat"

Yonatan Ayalon
  • 1,959
  • 18
  • 19
2

If you are using node js with express framework then script will not start using :

forever start app.js

First stop all running apps:

forever stopall

When this Express framework used it must be started with:

forever start ./bin/www
Sid Mhatre
  • 3,272
  • 1
  • 19
  • 38
1

First stop all running apps:

forever stopall

then use this command. It works for me and solved my issue:

forever -w ./bin/www

and you should find this in package.json file:

"scripts": {
    "start": "node ./bin/www"
  }

I hope it helps you.

dur
  • 15,689
  • 25
  • 79
  • 125
saghar.fadaei
  • 3,205
  • 1
  • 17
  • 10
1

One thing that also produces same kind of output, but doesn't start the application is if forever is unable to write to the specified log file. I had a case where the log file had become too big and this prevented the process from starting.

CaptainBli
  • 4,121
  • 4
  • 39
  • 58
Rami
  • 11
  • 2
1

Firstly change your package.json scripts like

"scripts": {
      "start": "forever ./bin/www.js"
 }

than start this command on linux console:sudo npm start

for windows just :npm start

Community
  • 1
  • 1
Vahap Gencdal
  • 1,900
  • 18
  • 17
1

I just ran into this today on an AWS Lightsail server, and NONE of the answers here or elsewhere had any effect. Everything worked fine until upgrading from NodeJS 10.x to 13.x. I tried removing and reinstalling forever, changing the permissions on the files and directories, etc, and I kept getting the EACCES error. The issue seemed to be that forever could not create directories within its .forever directory. The only thing that worked was to do the following:

1) Remove the .forever folder and all its subfolders and contents. For me, this was accomplished as follows: sudo rm -rf /home/bitnami/.forever

2) Manually recreate the .forever folder: sudo mkdir /home/bitnami/.forever

3) Manually set the permissions on the .forever folder: sudo chmod -R o+rwx /home/bitnami/.forever

4) Manually recreate the .forever/pids folder: sudo mkdir /home/bitnami/.forever/pids

5) Manually set the permissions on the .forever/pids folder: sudo chmod -R o+rwx /home/bitnami/.forever/pids

6) Manually recreate the .forever/sock folder: sudo mkdir /home/bitnami/.forever/sock

7) Manually set the permissions on the .forever/sock folder: sudo chmod -R o+rwx /home/bitnami/.forever/sock

8) Run my NodeJS app via forever again with the sudo command.

9) List the processes forever is running, and verify that my app was there.

I'm not sure why I had to go through all of this, as setting the permissions recursively should have done the same thing, but after doing this, forever started running perfectly as it did before.

Hope this helps someone.

user1353936
  • 124
  • 1
  • 4
0
forever stopall

cd /<app-folder>

forever -w ./bin/www

This just worked for me in a Google Cloud Bitnami VM

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 04 '22 at 15:09
-9

If you setup a module globaly (-g option) "forever" is in the $path

forever start app.js

should work.

PierrickP
  • 107
  • 7