问题
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