Forever detected script exited with code: 0 - node.js

I have a app4.js with content:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
I'm on Win10 cmd, I can success run it with node app4.js and get Example app listening on port 3000!,
but when I use forever -a forever.log start app4.js, it show error
Forever detected script exited with code: 0
Where is the problem? How to solve it?
Cmd Message:
D:\app>node app4.js
Example app listening on port 3000!
^C
D:\app>forever -a forever.log start app4.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
error: Forever detected script exited with code: 0
Another Answer say it's related to ./bin/www, but I can't understand what does it mean.

It means try moving your app.js code to the www file in the bin directory.
in .bin/www
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Also seems to be a known bug on certain versions of node/forever.
Issue

After some try I got it, here's my complete tring process:
1.In the beginning, I'm watching this video to learn forever, and at 10:24 it use forever start server.js and successfully run the server file.
2.Theoretically if I use forever start app4.js it should success, but I got error:
D:\app>forever start app4.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: app4.js
error: Cannot start forever
error: log file C:\Users\admin\.forever\forever.log exists. Use the -a or --append option to append log.
3.By the message, I think I should use -a to append log to some file, so I create a log file forever2.log under current folder, and use forever -a forever2.log start app4.js, the I got the error:
error: Forever detected script exited with code: 0
4.After some try, suddenly I look carefully to the nodejs book I'm reading, its example is forever start -l forever.log -o out.log -e err.log app.js, that is the -x is put between start and app.js, so I changed the command to forever start -a forever2.log app4.js and got
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: forever2.log
That is it's processing forever2.log, but what I want is app4.js
5.Finally I try forever start -a app4.js, and I got
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: app4.js
Then I run Browser at http://localhost:3000/, the Hello World! finally show!

Related

Nodejs forever pm

I am using a forever PM for my nodejs API.
I'm getting the following error while i try to start the app using forever.
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: hello.js
error: Cannot start forever
error: log file /home/user/.forever/forever.log exists. Use the -a or --append option to append log.
user#testub002:~$
Thanks in advance.
It seems your problem is that you need to either delete /home/user/.forever/forever.log each time you run forever or execute forever -a hello.js

Forever dont want to start

I learning NodeJS. I have ubuntu 16 server with installed nodejs. Then i install globally express-generator and forever. Next i maked a folder into /var/www named as hack-it-up.ru and used express-generator to generate the app. Next i changed port of my app as 8081 and tryed to start it with npm start. All works fine. But... when i tryed to start my app with forever, i got errors. I readed lots of guides but didnt solved it. Help me please. Thanks!
root#ashipka:/var/www/hack-it-up.ru# forever start -l /var/www/forever-logs/hack-it.log -a 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
root#ashipka:/var/www/hack-it-up.ru# forever list
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] aj4I /usr/local/bin/node app.js 27060 27066 /root/.forever/aj4I.log STOPPED
data: [1] wFf4 /usr/local/bin/node app.js 27147 27153 /var/www/forever-logs/hack-it.log STOPPED
root#ashipka:/var/www/hack-it-up.ru# forever stop 0
error: Forever cannot find process with id: 0
I needed to start from bin/www file instead of app.js as said Mohit Bhardwaj. Thanks! All works fine.

error: Forever detected script exited with code: 0

I have a simple script to watch change in file,
index.js
var watch = require('node-watch');
watch('C:\CRM\log.txt', function(filename) {
console.log(filename, ' changed.');
});
I am trying to run it via command
forever start index.js
Its showing output:
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: index.js
and the control is returning to command prompt, instead of staying there! How can I keep it running and get the console.log output as soon as file is changed?
forever start index.js will start up in the background. From the sounds of it, you want it to stay in the foreground. Use forever index.js instead.

Forever not working with sailsjs

I've installed forever using
npm install forever -g
I've set config in modeljs to safe
migrate: 'safe'
Still when I run
forever -w start app.js
I get this
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
I dont want to stop and start my app using sails lift everytime I'm making a change. I'm using sails version of 0.11.
Used sails-hook-autoreload in the end which did the same job with ease.

nodejs forever: File config.json not found or is invalid

I have strange problem with nodejs forever.
I have cloned iodocs to /home/user/iodocs
If I start forever from iodocs directory:
user#ubuntu:~/iodocs$ forever start app.js
everything is working fine.
If I try start forever from another directory, for example:
user#ubuntu:~$ forever start --sourceDir /home/user/iodocs/ 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
In log file I have seen:
user#ubuntu:~$ forever logs
info: Logs for running Forever processes
data: script logfile
data: [0] /home/user/iodocs/app.js /home/user/.forever/xYBf.log
user#ubuntu:~$ cat /home/user/.forever/xYBf.log
File /home/user/config.json not found or is invalid. Try: `cp config.json.sample config.json`
error: Forever detected script exited with code: 1
Why forever try to read config from unix user home directory instead sourceDir?
How to fix it?

Resources