node.js nodemon 无法正常工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23927195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nodemon not working properly
提问by bruceparker
I am running my nodejs app by npm start
我正在运行我的 nodejs 应用程序 npm start
I just installed nodemon by
sudo npm install -g nodemonso that i can get my server restarted when i save changes to files.
我刚刚安装了 nodemon,
sudo npm install -g nodemon以便在保存对文件的更改时可以重新启动服务器。
But when i try to start the server, something like this
但是当我尝试启动服务器时,像这样
nodemon ./app.js localhost 3000 or nodemon start localhost 3000
nodemon ./app.js localhost 3000 or nodemon start localhost 3000
I get this as output
我得到这个作为输出
LM-SJC-00871929:webapp gdeep$ nodemon ./app.js localhost 3000
28 May 23:34:30 - [nodemon] v1.1.1
28 May 23:34:30 - [nodemon] to restart at any time, enter `rs`
28 May 23:34:30 - [nodemon] watching: *.*
28 May 23:34:30 - [nodemon] starting `node ./app.js localhost 3000`
but when i go to my webpage, i get
但是当我去我的网页时,我得到
Oops! Google Chrome could not connect to localhost:3000. What am i doing wrong?
Oops! Google Chrome could not connect to localhost:3000. 我究竟做错了什么?
App.js here http://collabedit.com/t35dy
App.js 在这里http://collabedit.com/t35dy
回答by SomeKittens
You're running express 4, which has the app.listencall in a different file than app.js. The command you're looking for is nodemon bin/www(localhostand 3000are not needed in this scenario).
您正在运行 express 4,它app.listen在与app.js. 你要找的命令是nodemon bin/www(localhost而且3000在这种情况下并不需要)。
In fact, you can even run nodemonwith no args, and it'll read what command needs to be run from scripts.startin package.json(which express generates automatically).
事实上,你甚至可以nodemon在没有参数的情况下运行,它会读取需要从scripts.startin运行的命令package.json(express 自动生成)。
回答by Garth
In my case, I had to install nodemon globally. Use this command to do so..
就我而言,我必须全局安装 nodemon 。使用此命令执行此操作..
npm install -g nodemon
If you're using Linuxyou may need to prefix the command with the sudo keyword for administration access..
如果您使用的是Linux,您可能需要在命令前加上 sudo 关键字以进行管理访问。
sudo npm install -g nodemon
回答by BHUVNESH KUMAR
Add following code in your code
在您的代码中添加以下代码
app.jsapp.listen(3000, function(){ console.log("info",'Server is running at port : ' + 3000); });package.jsonnodemon app.js
app.jsapp.listen(3000, function(){ console.log("info",'Server is running at port : ' + 3000); });package.jsonnodemon app.js
Then run npm startfrom the command line.
然后从命令行运行npm start。
回答by Dinesh
For Express.js 4,
use nodemon
or
nodemon bin/www
对于 Express.js 4,
使用 nodemon
或
nodemon bin/www
回答by user3607134
try running nodemon ./app.js 3000 or nodemon start 3000
尝试跑步 nodemon ./app.js 3000 or nodemon start 3000
回答by Skoua
Here's what I did to make nodemon update correctly:
这是我为使 nodemon 正确更新所做的工作:
nodemon index.js -L
The -Lflag stands for legacyWatch, here's an explanation from the official doc:
该-L标志代表legacyWatch,这是官方文档的解释:
In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enables Chokidar's polling.
在某些网络环境中(例如运行 nodemon 读取已安装驱动器的容器),您将需要使用 legacyWatch: true 来启用 Chokidar 的轮询。
https://www.npmjs.com/package/nodemon#application-isnt-restarting
https://www.npmjs.com/package/nodemon#application-isnt-restarting
回答by Yue Yin
If you are using express4, the easiest way is to navigate to package.json and change
"scripts": {
"start": "node ./bin/www"
}
如果您使用 express4,最简单的方法是导航到 package.json 并更改
"scripts": {
"start": "node ./bin/www"
}
to
"scripts": {
"start": "nodemon ./bin/www"
}
到
"scripts": {
"start": "nodemon ./bin/www"
}
回答by Sheshadri H
try
尝试
npm install --save-dev nodemon
and then
in
package.json filekeep like this
然后
package.json file像这样保持
"scripts": {
"start": "nodemon",
"test": "echo \"Error: no test specified\" && exit 1"
},
instead of npx nodemon, which takes more time
而不是 npx nodemon,这需要更多时间
回答by Hymanal
For Express 4; Just run
对于快递 4;赶紧跑
nodemon
节点监视器
command (with out any args) on the directory; this works for me.
目录上的命令(不带任何参数);这对我有用。
回答by czerasz
You might also run into the issue of having an empty .nodemonignore.
您可能还会遇到空的.nodemonignore.

