【发布时间】:2012-02-15 14:27:03
【问题描述】:
我发现forever可以永远运行nodejs服务器。是永远支持这个功能吗?
-- If the nodejs script is modified changed, the server shld restarted automatically.
如何永久启用此功能?还是我需要别的东西?
【问题讨论】:
我发现forever可以永远运行nodejs服务器。是永远支持这个功能吗?
-- If the nodejs script is modified changed, the server shld restarted automatically.
如何永久启用此功能?还是我需要别的东西?
【问题讨论】:
来自forever readme。使用-w 标志来观察文件的变化。
【讨论】:
-w 监视目录文件和子目录'
以防其他人,比如我自己,通过谷歌找到这个。
我必须这样运行它:
forever --watch ./start/file
至少对我来说,它默认会监视我正在运行命令的当前目录以进行更改。 ./start/file 是“npm start”从你的 package.json 中找到的文件。
如果您需要查看与您的密码显示您所在位置不同的目录,请尝试:
forever --watch --watchDirectory ./path/to/dir ./start/file
出于某种原因,“永远开始 xxxxxxxxx”只会为我带来帮助信息,但这有效。 /我耸了耸肩。
【讨论】:
forever start --watch --watchDirectory ./ index.js
又是它的另一个用法示例(它确实有效:D)
forever -w --watchDirectory . --watchIgnore *.log -o ./log/out.log -e ./log/err.log index.js
这将在同一进程中启动应用程序并输出到 stdout/stderr(但也写入日志)
在 prod 监视中启动它显然不是一个好主意,并且将它作为一个守护进程运行可能是你想要的,所以删除 -w 标志并添加“start”命令
forever -o ./log/out.log -e ./log/err.log start index.js
【讨论】:
我个人使用Nodemon 来处理这个问题。它是节点服务器的替代品。当您的文件更新时,它会自动重新启动服务器。您可能想检查一下。
【讨论】: