Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - Unable to run node server using forever

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!

like image 396
S Singh Avatar asked May 23 '13 13:05

S Singh


People also ask

How do I permanently run node js server?

js application locally after closing the terminal or Application, to run the nodeJS application permanently. We use NPM modules such as forever or PM2 to ensure that a given script runs continuously. NPM is a Default Package manager for Node.

Why do you use forever with node js?

Forever is an npm module that ensures a Node. js script continuously runs in the background on the server. It's a helpful CLI tool for the production environment because it helps manage the Node applications and their processes.

How much RAM is required for node JS?

256 MB is sufficient amount of RAM to run Node. js (e.g. on Linux VPS instance), assuming no other memory-hog software is run.


Video Answer


3 Answers

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 ~]#
like image 139
Mike S. Avatar answered Oct 16 '22 19:10

Mike S.


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"

like image 4
Yonatan Ayalon Avatar answered Oct 16 '22 19:10

Yonatan Ayalon


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
like image 2
Sid Mhatre Avatar answered Oct 16 '22 20:10

Sid Mhatre