更改文件后重新启动节点 [英] Restart node upon changing a file
问题描述
对于那些来自PHP背景的人来说,杀死节点并在每次代码更改后重新启动它的过程似乎非常繁琐.在使用节点启动脚本以保存代码更改后自动重新启动节点时,是否有任何标志?
For someone who is coming from PHP background the process of killing node and starting it again after every code change, seems very tedious. Is there any flag when starting a script with node to automatically restart node when code change is saved?
推荐答案
永远模块的概念是多个node.js服务器,并且可以启动,重新启动,停止和列出当前正在运行的服务器.它还可以监视文件的更改并根据需要重新启动节点.
forever module has a concept of multiple node.js servers, and can start, restart, stop and list currently running servers. It can also watch for changing files and restart node as needed.
如果尚未安装,请安装:
Install it if you don't have it already:
npm install forever -g
安装后,调用forever
命令:使用-w
标志监视文件中的更改:
After installing it, call the forever
command: use the -w
flag to watch file for changes:
forever -w ./my-script.js
此外,您可以监视目录并忽略模式:
In addition, you can watch directory and ignore patterns:
forever --watch --watchDirectory ./path/to/dir --watchIgnore *.log ./start/file
这篇关于更改文件后重新启动节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!