NodeJS - nodemon 没有重新启动我的服务器
NodeJS - nodemon not restarting my server
我安装了 NodeJS (4.4.5),然后继续安装 nodemon (1.9.2),
我遵循所有安装说明 (npm install -g nodemon)
我创建了一个新文件夹,里面有我的 server.js 和一些基本代码:
var http = require('http');
http.createServer(function (request, response){
response.writeHead( 200, {'Content-Type': 'text/plain'} );
response.write("Hello world");
response.end();
}).listen(3000, 'localhost');
console.log('http://localhost:3000');
所以当我 运行 在我的控制台 "nodemon server.js" 我得到这个:
[nodemon] 1.9.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
http://localhost:3000
(这意味着运行宁可以)
但是当我对 server.js 进行一些更改时,它不会重新启动服务器
可能是什么问题?
我在 nodemon 1.9.2 上遇到了同样的问题:nodemon 监视了 0 个文件
(尝试详细模式 nodemon server.js -V
以获得更多信息)
经过一番研究,这个问题是由于我的根目录名称引起的:
我的根目录被命名为 "mysite.git" 因此 nodemon 正在监视 0 个文件。我在没有点的情况下重命名了我的根目录,现在 nodemon 可以正常工作了。
从您的根目录中删除所有特殊字符,nodemon 应该会按预期工作。
在某些网络环境中(例如容器 运行 nodemon 读取已安装的驱动器),您将需要使用启用 Chokidar 轮询的 legacyWatch: true。
通过 CLI,使用 --legacy-watch 或 -L 简称:
nodemon -L
只需确保添加到脚本 -> 开始 --legacy-watch ./app
"scripts": {
"start": "nodemon --legacy-watch ./app ./bin/www "
},
我刚刚遇到了似乎是同一个问题,我会更改我的代码并保存它们,但 nodemon 不会重新启动我的服务器。我可以更新的唯一方法是通过控制台中的 'rs'。我在这里结束寻找解决方案,但后来决定重新安装 nodemon,因为没有很好的解释为什么它不起作用:
npm uninstall nodemon
npm install nodemon
重新安装后,代码更改时自动重启有效。
像这样编辑 package.json 文件:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js",
},```
This may help you.
你可以尝试 运行ning 这样的 nodemon -L yourapp.js
,像这样的事情:
"scripts": {
"start": "node index.js",
"dev": "nodemon -L index.js "
}
和运行命令:
npm run dev
这对我有用!
Nodemon 使用 SIGUSR2
信号来重启服务器,交叉检查你的服务器是否覆盖了这个进程信号的功能。
在我的例子中,我使用的是 heapdump 模块,它正在重置这个信号,因此我使用以下命令启动了服务器:-
env NODE_HEAPDUMP_OPTIONS=nosignal nodemon app.js
这对我有用。
我在 YouTube 上找到了解决方案。所以,解决方案是:
- 复制此路径:
C:\Windows\System32
- 进入 'computer/This Pc' 属性然后进入 'Advance System Settings/System Settings'.
- 然后点击 'Environment variable' 按钮。
- 然后双击“用户变量”部分中的 'Path'。
- 然后单击 'New' 并粘贴此路径:
C:\Windows\System32
我遇到了同样的问题。我尝试卸载 nodemon,但没有用。如果可行,您可以尝试全局卸载 nodemon。它在我的情况下不起作用,所以我所做的是从我的系统中删除所有节点模块。它们位于 C:/users/user/AppData/Roaming/npm。我什至将node重新安装到我的系统中,然后安装了nodemon,然后就可以了。
我安装了 NodeJS (4.4.5),然后继续安装 nodemon (1.9.2), 我遵循所有安装说明 (npm install -g nodemon)
我创建了一个新文件夹,里面有我的 server.js 和一些基本代码:
var http = require('http');
http.createServer(function (request, response){
response.writeHead( 200, {'Content-Type': 'text/plain'} );
response.write("Hello world");
response.end();
}).listen(3000, 'localhost');
console.log('http://localhost:3000');
所以当我 运行 在我的控制台 "nodemon server.js" 我得到这个:
[nodemon] 1.9.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
http://localhost:3000
(这意味着运行宁可以)
但是当我对 server.js 进行一些更改时,它不会重新启动服务器
可能是什么问题?
我在 nodemon 1.9.2 上遇到了同样的问题:nodemon 监视了 0 个文件
(尝试详细模式 nodemon server.js -V
以获得更多信息)
经过一番研究,这个问题是由于我的根目录名称引起的: 我的根目录被命名为 "mysite.git" 因此 nodemon 正在监视 0 个文件。我在没有点的情况下重命名了我的根目录,现在 nodemon 可以正常工作了。
从您的根目录中删除所有特殊字符,nodemon 应该会按预期工作。
在某些网络环境中(例如容器 运行 nodemon 读取已安装的驱动器),您将需要使用启用 Chokidar 轮询的 legacyWatch: true。
通过 CLI,使用 --legacy-watch 或 -L 简称:
nodemon -L
只需确保添加到脚本 -> 开始 --legacy-watch ./app
"scripts": {
"start": "nodemon --legacy-watch ./app ./bin/www "
},
我刚刚遇到了似乎是同一个问题,我会更改我的代码并保存它们,但 nodemon 不会重新启动我的服务器。我可以更新的唯一方法是通过控制台中的 'rs'。我在这里结束寻找解决方案,但后来决定重新安装 nodemon,因为没有很好的解释为什么它不起作用:
npm uninstall nodemon
npm install nodemon
重新安装后,代码更改时自动重启有效。
像这样编辑 package.json 文件:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js",
},```
This may help you.
你可以尝试 运行ning 这样的 nodemon -L yourapp.js
,像这样的事情:
"scripts": {
"start": "node index.js",
"dev": "nodemon -L index.js "
}
和运行命令:
npm run dev
这对我有用!
Nodemon 使用 SIGUSR2
信号来重启服务器,交叉检查你的服务器是否覆盖了这个进程信号的功能。
在我的例子中,我使用的是 heapdump 模块,它正在重置这个信号,因此我使用以下命令启动了服务器:-
env NODE_HEAPDUMP_OPTIONS=nosignal nodemon app.js
这对我有用。
我在 YouTube 上找到了解决方案。所以,解决方案是:
- 复制此路径:
C:\Windows\System32
- 进入 'computer/This Pc' 属性然后进入 'Advance System Settings/System Settings'.
- 然后点击 'Environment variable' 按钮。
- 然后双击“用户变量”部分中的 'Path'。
- 然后单击 'New' 并粘贴此路径:
C:\Windows\System32
我遇到了同样的问题。我尝试卸载 nodemon,但没有用。如果可行,您可以尝试全局卸载 nodemon。它在我的情况下不起作用,所以我所做的是从我的系统中删除所有节点模块。它们位于 C:/users/user/AppData/Roaming/npm。我什至将node重新安装到我的系统中,然后安装了nodemon,然后就可以了。