简体   繁体   English

使用 nodeJS/永远忽略配置文件

[英]Ignore config file with nodeJS/forever

Sorry for the (probably) bad question....对不起(可能)不好的问题......

I have searched a lot, and have not been able to find a simple example of how to exclude a specific file (or folder, it doesn't matter) from my forever watchlist.我已经搜索了很多,但没有找到一个简单的例子来说明如何从我的永久监视列表中排除特定文件(或文件夹,没关系)。

the server runs with forever -w app.js服务器以永远 -w app.js 运行

everytime i update the config file of the app (public/config.json), the server restarts.每次我更新应用程序的配置文件 (public/config.json) 时,服务器都会重新启动。

All the readmes and explanations are REALLY cryptic and i have NO idea how to use it (from the CLI)所有的自述文件和解释都非常神秘,我不知道如何使用它(来自 CLI)

would somebody be so kind and tell me how to start my server without restarting on every update of that file?有人会这么好心告诉我如何在不重新启动该文件的每次更新的情况下启动我的服务器吗? (no problem to migrate it to a seperate folder, if that is an issue) (如果这是一个问题,可以将其迁移到单独的文件夹中)

thanks谢谢

Forever - A simple CLI tool for ensuring that a given node script runs continuously. Forever - 一个简单的 CLI 工具,用于确保给定的节点脚本连续运行。 There are two ways to use forever : through the command line or by using forever in your code.有两种使用forever :通过命令行或在代码中使用永远。

Command Line Usage -命令行用法-

forever [action] [options] SCRIPT

There are so many options you can use with forever command.有很多选项可以与永久命令一起使用。 To see this run below command -要在命令下查看此运行 -

forever --help

When forever command is executed with option --watch then any changes made into the file in the project folder or sub-folder, forever restarted script automatically.当使用选项--watch执行永远命令时,对项目文件夹或子文件夹中的文件所做的任何更改,永远自动重新启动脚本。

Example - Let take an example of node.js application.示例 -让我们以 node.js 应用程序为例。

forever --watch app.js

For some reason we want to ignore script restart automatically like when any changes made in html views it doesn't restart script.出于某种原因,我们希望自动忽略脚本重新启动,就像在 html 视图中所做的任何更改一样,它不会重新启动脚本。

--watchIgnore allow you to ignore pattern when watch is enabled. --watchIgnore允许您在启用监视时忽略模式。

Example -例子 -

forever --watch app.js --watchIgnore

The forever command used with option --watchIgnore looks .foreverignore , if it not found in you project directory then print an error into the console like this -与选项 --watchIgnore .foreverignore使用的永远命令看起来是.foreverignore ,如果在你的项目目录中找不到它,那么像这样在控制台中打印一个错误 -

error: Could not read .foreverignore file.
error: ENOENT: no such file or directory, open 'project_folder/.foreverignore'

So found such type of error then create a .foreverignore file into the project folder with appropriate pattern you want to ignore.因此,发现此类错误,然后使用要忽略的适当模式在项目文件夹中创建一个.foreverignore文件。

.foreverignore file sample .foreverignore 文件示例

node_modules
public
*ignore*
**.log**

Hope this will help you to resolve your issue !!希望这能帮助您解决您的问题!!

Thanks for the .foreverignore part @Vikash-Kumar As of v3.0.2 the --watchIgnore is not needed for .foreverignore I guess.感谢 .foreverignore 部分 @Vikash-Kumar 从 v3.0.2 开始,我猜 .foreverignore 不需要 --watchIgnore。 The contents in .foreverignore are automatically ignored without the flag --watchIgnore. .foreverignore 中的内容会在没有标志 --watchIgnore 的情况下被自动忽略。 Infact adding the flag without any additional filtering conditions does not seems to work at all.事实上,在没有任何额外过滤条件的情况下添加标志似乎根本不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM