gulp nodemon + node =错误:监听EADDRINUSE [英] gulp nodemon + node = Error: listen EADDRINUSE

查看:483
本文介绍了gulp nodemon + node =错误:监听EADDRINUSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道EADDRINUSE发生在节点尝试将自己绑定到已经在使用的端口上时。



问题在于,当我的代码发生更改时,这一切都与gulp nodemon结合使用以重新启动。我有一种感觉,我得到这个错误,因为我把我的代码从bin / www移动到我的app.js文件中。



/ bin看起来像这样:

 #!/ usr / bin / env节点
var app = require('../ app');

gulp.js使用以下代码重新启动我的服务器:

  // nodemon任务
gulp.task('nodemon',function(){
nodemon({script:'bin / www',ext: 'html js'})
.on('change',['styles-website','watch','test'])
.on('restart',function(){
console.log('restarted nodemon!')
})
});

在我的app.js文件中我有这个启动服务器:

  var server = app.listen(app.get('port'),function(){
console.log(Express server started! );
});

第一次启动gulp时,这一切都正常,但现在当gulp重新启动时,出现错误:

 错误:听EADDRINUSE 

我有一种感觉,这与将代码移出bin / www(必须让我的app var中的socket.io工作)有关。



更新:当使用nodemon bin / www之外的所有内容时,它都可以正常工作

解决方案

如果任何人有同样的问题,这似乎解决了这个问题:

<$ ($ {code> .pipe(livereload({auto:false}))

auto:false选项可防止重新启动livereload服务器的另一个实例

I know EADDRINUSE happens when node tries to bind itself to a port that's already in use.

The problem is that this all worked in combination with gulp nodemon to restart when changes occur in my code. I have a feeling I'm getting this error, ever since I moved my code from bin/www into my app.js file.

bin/www looks like this:

#!/usr/bin/env node
var app = require('../app');

gulp.js restarts my server with this code:

// nodemon task
gulp.task('nodemon', function(){
  nodemon({ script: 'bin/www', ext: 'html js' })
  .on('change', ['styles-website', 'watch', 'test'])
  .on('restart', function(){
    console.log('restarted nodemon!')
  })
});

in my app.js file I have this to start the server:

var server = app.listen(app.get('port'), function() {
  console.log("Express server started!");
});

This all works fine the first time I start gulp, but now when gulp restarts I get the error:

Error: listen EADDRINUSE

I have a feeling this has something to do with moving the code out of bin/www (necessary to get socket.io working on my app var)

Does anyone have an idea on how to solve this?

UPDATE: when using "nodemon bin/www" outside of gulp, it all works fine

解决方案

If anyone is having the same issue, this seems to solve it:

.pipe(livereload({ auto: false }))

The auto:false option prevents restarting another instance of the livereload server

这篇关于gulp nodemon + node =错误:监听EADDRINUSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆