简体   繁体   English

永远检测到的脚本已退出,代码为:0

[英]Forever detected script exited with code: 0

I have a app4.js with content: 我有一个内容为app4.js的内容:

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! 我在Win10 cmd ,我可以使用node app4.js成功运行它,并获得Example app listening on port 3000! ,

but when I use forever -a forever.log start app4.js , it show error 但是当我forever -a forever.log start app4.js使用forever -a forever.log start app4.js ,它显示错误

Forever detected script exited with code: 0 永远检测到的脚本已退出,代码为:0

Where is the problem? 问题出在哪儿? How to solve it? 怎么解决呢?


Cmd Message: Cmd讯息:

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. 另一个答案说它与./bin/www有关,但我不明白这是什么意思。

It means try moving your app.js code to the www file in the bin directory. 这意味着尝试将您的app.js代码移动到bin目录中的www文件。

in .bin/www 在.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. 1.一开始,我正在观看该视频以进行forever学习,并在10:24 forever start server.js使用forever start server.js并成功运行服务器文件。


2.Theoretically if I use forever start app4.js it should success, but I got error: 2.从理论上讲,如果我使用forever start app4.js它将成功,但是出现错误:

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: 3.By的消息,我想我应该用-a附加日志某些文件,所以我创建日志文件forever2.log当前文件夹下,并使用forever -a forever2.log start app4.js中,我得到了错误:

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 4,经过一番尝试后,突然我仔细看了看我正在阅读的nodejs书,它的例子是forever start -l forever.log -o out.log -e err.log app.js ,即-x被放在startapp.js之间,因此我将命令更改为forever start -a forever2.log 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: forever2.log

That is it's processing forever2.log , but what I want is app4.js 那是它正在处理forever2.log ,但是我想要的是app4.js


5.Finally I try forever start -a app4.js , and I got 5,最后我尝试forever start -a 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

Then I run Browser at http://localhost:3000/ , the Hello World! 然后我在Hello World的 http://localhost:3000/运行Browser finally show! 终于秀了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM