nodemon递归监视问题?

时间:2017-02-18 17:01:06

标签: node.js express nodemon

我已经使用命令安装了nodemon:

npm install nodemon -g

完成后我将"start": "node ./bin/www"更改为"start": "nodemon ./bin/www"

在运行npm start时控制台输出:

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `nodemon  ./bin/www ./bin/www`
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `nodemon  ./bin/www ./bin/www ./bin/www`
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `nodemon  ./bin/www ./bin/www ./bin/www ./bin/www`
and so on....

我哪里错了?请记住,这是我在nodejs上的第3天,所以请保持简单。

修改

 "scripts": {
    "start": "nodemon app.js"
  },

enter image description here

enter image description here

“nodemon app.js”似乎有效,因为控制台没有显示任何错误但是我无法运行该应用程序。但是,如果我将其更改回node ./bin/www,则可以正常工作。

4 个答案:

答案 0 :(得分:2)

尝试降级要求。 这帮助了我。

npm install nodemon@1.0.0 -g

我在docker image(node:alpine)中使用nodemon> 1.2.0 100%重现了这个问题。而v1.1.0和v1.2.0也有一些奇怪的问题。

我只检查了次要版本(没有检查补丁级别,例如1.2.1,1.2.2和其他版本)

因此。 1.0.0很旧,但效果很好。

在我的主机Mac上,我全局安装了nodemon@1.11.0。 有时我有这个问题,有时候我没有。 这与pwd和nodemon.json文件有某种联系。但我不确定。

我找到了与此问题相关的bug report

答案 1 :(得分:0)

您无需告诉nodemon要观看的文件夹。您只需要告诉它运行您的主应用程序,它将自动监视所有嵌套的文件夹和文件。

例如。 nodemon app.js(如果app.js是您的申请)

另外。您可以选择在应用程序的主体中创建一个nodemon.json文件来存放nodemon的配置信息。与你的问题没有关系。但很高兴:)

以下是我的看法:

{
  "ignore": ["data/*.json", "/node_modules/", "README.md"]
}

答案 2 :(得分:0)

试试这个:

  

npm i -D nodemon

package.json中的

添加:

"scripts": {
    "start": "nodemon index.js",
  }

这将执行应用程序节点根目录中的文件index.js。 例如:

  

应用程序/
       node_modules
       index.js

再试一次:

  

npm start

答案 3 :(得分:0)

您正在观看一个不存在的文件,这将导致无限循环。

在您的情况下,您正在运行./bin/www并查看您的IDE屏幕截图,您有./bin/www.js

这就是nodemon app.js没有错误的原因。虽然我无法保证上班,但试试nodemon ./bin/www.js

然后,在不查看代码的情况下,我不确定为什么您无法以这种方式连接您的应用程序。

有关详情,请查看@matt answer和nodemon docs