简体   繁体   中英

gulp nodemon + node = Error: listen EADDRINUSE

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM