automatically restarting service via forever for nodejs [duplicate]

末鹿安然 提交于 2019-12-31 11:21:49

问题


I found that forever can run nodejs server forever. Is forever supports this feautre?

-- If the nodejs script is modified changed, the server shld restarted automatically.

How can I enable this feature using forever? or I need something else?


回答1:


I personally use Nodemon to handle that. Its a replacement for the node server. It automatically restarts the server when your files are updated. You might want to check it out.




回答2:


From the forever readme. Use the -w flag to watch file for changes.




回答3:


In case someone else, like myself, comes to find this through google.

I have to run it thusly:

forever --watch ./start/file

For me, at least, it defaults to watching the current directory I'm running the command in for changes. ./start/file is the file that "npm start" hits up from your package.json.

If you need to watch a different directory from where you're pwd shows you to be, try:

forever --watch --watchDirectory ./path/to/dir ./start/file

For some reason "forever start xxxxxxxxx" only brings up the help information for me, but this works. /me shrugs.




回答4:


Again just another example of its usage (and it does work :D)

forever -w --watchDirectory . --watchIgnore *.log -o ./log/out.log -e ./log/err.log index.js

That will launch the app in the same process with output to stdout/stderr (but also written to the logs)

To launch it in prod watching is obviously not a good idea and running it as a deamon is probably what you are after so drop the -w flags and add the "start" command

forever -o ./log/out.log -e ./log/err.log start index.js


来源:https://stackoverflow.com/questions/8951297/automatically-restarting-service-via-forever-for-nodejs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!