gulp nodemon + node = Error: listen EADDRINUSE

。_饼干妹妹 提交于 2019-12-24 11:05:01

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/26404954/gulp-nodemon-node-error-listen-eaddrinuse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!