为nodejs永远自动重启服务

cou*_*011 11 node.js forever

我发现永远可以永远运行nodejs服务器.是永远支持这个feautre?

-- If the nodejs script is modified changed, the server shld restarted automatically.
Run Code Online (Sandbox Code Playgroud)

如何永久使用此功能?还是我需要别的东西?

fen*_*ent 31

永远的自述.使用该-w标志来查看文件以进行更改.


Cri*_*aki 15

万一其他人,比如我自己,通过谷歌来找到这个.

我必须这样运行它:

forever --watch ./start/file
Run Code Online (Sandbox Code Playgroud)

对我来说,至少,默认情况下,我正在查看当前正在运行命令的目录以进行更改../start/file是"npm start"从package.json中命中的文件.

如果您需要在pwd显示的位置观看不同的目录,请尝试:

forever --watch --watchDirectory ./path/to/dir ./start/file
Run Code Online (Sandbox Code Playgroud)

出于某种原因,"永远启动xxxxxxxxx"只会为我提供帮助信息,但这有效./我耸了耸肩.


小智 6

再次只是它的另一个使用示例(它确实有效:D)

forever -w --watchDirectory . --watchIgnore *.log -o ./log/out.log -e ./log/err.log index.js
Run Code Online (Sandbox Code Playgroud)

这将在相同的过程中启动应用程序,输出到stdout/stderr(但也写入日志)

在prod观看中启动它显然不是一个好主意,并且将其作为deamon运行可能就是你之后所以删除-w标志并添加"start"命令

forever -o ./log/out.log -e ./log/err.log start index.js
Run Code Online (Sandbox Code Playgroud)


Vin*_*opi -1

我个人使用Nodemon来处理这个问题。它是节点服务器的替代品。当您的文件更新时,它会自动重新启动服务器。您可能想检查一下。