如何在 Windows 上使用永久模块停止 Node.js 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14556852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:01:59  来源:igfitidea点击:

How to stop Node.js application using forever module on Windows?

node.jsjavascript-events

提问by Satyendra Fauzdar

I have gone through so many questions regarding forever module for nodejs APP, but did not find my answer.

我已经解决了很多关于 nodejs APP 的永久模块的问题,但没有找到我的答案。

Forevermodule is working fine on a Linux box but now I am putting my APP on Windows 7 and trying to run it with forever. First i installed forever module as

Forever模块在 Linux 机器上运行良好,但现在我将我的应用程序放在 Windows 7 上并尝试永远运行它。首先我安装了永远的模块

npm install forever -g

after that i ran my app as

之后我运行我的应用程序

forever start app.js

it's running fine by saying file app.js is running with forever and I am accessing my app successfully.

它运行良好,说文件 app.js 永远运行,我正在成功访问我的应用程序。

When I execute a command forever stop app.jsI get the error

当我执行命令时forever stop app.js出现错误

no forever file is running

没有永久文件正在运行

Please suggest me if anyone has used forever on windows that how can i stop my application on Windows.

如果有人在 Windows 上永远使用过,请建议我如何在 Windows 上停止我的应用程序。

回答by laktak

use forever listthen forever stop with the id, e.g. forever stop 0

使用forever list然后永远停止与 id,例如forever stop 0

Here is a sample output

这是一个示例输出

user@some-server]$ forever list
info:    Forever processes running
data:        uid  command                                                  script forever pid   id logfile                          uptime        
data:    [0] 9Xzw ng serve --host 0.0.0.0 --port 4009         13164   29579    /home/ec2-user/.forever/9Xzw.log 7:1:20:50.412 
data:    [1] wOj1 npm run-script app-start-dev                                    29500   24978    /home/ec2-user/.forever/wOj1.log 0:0:5:3.433

Here 0is like an index which is in the first column of the output. If there are two processes running, we can use indexes like 0or 1to stop the first or the second process.

0就像在输出的第一列中的索引。如果有两个进程在运行,我们可以使用像01这样的索引来停止第一个或第二个进程。

forever stop 0OR forever stop 1

forever stop 0或者 forever stop 1

回答by Morgan Herlocker

I had this same issue and found that it was because I was running forever start with sudo (on Linux) so that I could run a production site on port 80. This did the trick:

我遇到了同样的问题,发现这是因为我一直在以 sudo 开头(在 Linux 上)运行,以便我可以在端口 80 上运行生产站点。这确实成功了:

sudo forever list

回答by delliottg

This is just to expand on @laktak's answer. The result of forever liston Windows will look something like this:

这只是为了扩展@laktak 的回答。forever list在 Windows 上的结果将如下所示:

info:    Forever processes running
data:        uid  command              script                          forever p
id   id logfile                               uptime
data:    [0] an1b "C:\nodejs\node.exe" C:\sbSerialWidget\server.js 8780    1
0152    C:\Users\username\.forever\an1b.log STOPPED

I wasn't sure which one was the ID initially, but I figured out that it was the first entry after the second datafield above, so the line you're interested in is with the ID bolded & italicized:

我最初不确定哪个是 ID,但我发现它是data上面第二个字段之后的第一个条目,所以您感兴趣的行是带有粗体和斜体的 ID:

data: [0]an1b C:\nodejs\node.exeC:\sbSerialWidget\server.js8780 1 0152 C:\Users\username.forever\an1b.log STOPPED

数据: [0]an1b C:\nodejs\node.exeC:\sbSerialWidget\server.js8780 1 0152 C:\Users\username.forever\an1b.log STOPPED

So to stop this particular instance, you'd run:

所以要停止这个特定的实例,你需要运行:

forever stop 0

forever stop 0

Hope this helps someone else who was confused like I was

希望这能帮助像我一样困惑的其他人

回答by Ilya Zaytsev

It's a bug in windows https://github.com/nodejitsu/forever/issues/337If you need to stop your app just open task manager and find node.js process and kill it. Hard but work.

这是 Windows https://github.com/nodejitsu/forever/issues/337 中的一个错误 如果您需要停止您的应用程序,只需打开任务管理器并找到 node.js 进程并杀死它。辛苦但工作。