1

I'd like to start my NodeJS application using BrowserSync but it seems not working.

Error message : Error: listen EADDRINUSE

Edit #1:

I found this way to resolve my issue.

gulp.task('sync', ['start', 'watch'], function(cb) { browserSync.init({ files: ['**/*'], proxy: 'http://localhost:3000', port: 4000 }); }); gulp.task('start', function() { var called = false; return nodemon({ script: './bin/www', watch: ['Application.js'] }).on('start', function onStart() { if (!called) { cb(); } called = true; }).on('restart', function onRestart() { setTimeout(function reload() { browserSync.reload({ stream: false }); }, 500); }); });

1

1 Answer 1

5

EADDRINUSE means that the port number which listen() tries to bind the server to is already in use. So, in your case, there must be running a server on port 80 already. If you have another webserver running on this port you will get the EADDRINUSE error.

var gulp = require('gulp'); var browserSync = require('browser-sync'); var nodemon = require('gulp-nodemon'); gulp.task('default', ['browser-sync'], function () { }); gulp.task('browser-sync', ['nodemon'], function() { browserSync.init(null, { proxy: "http://localhost:5000", files: ["**/*.*"], browser: "google chrome", port: 7000, }); }); gulp.task('nodemon', function (cb) { nodemon({ script: './bin/www/app.js' }) .on('start', function () { cb(); }) .on('error', function(err) { // Make sure failure causes gulp to exit throw err; }); }); 

Hope it helps :)

Sign up to request clarification or add additional context in comments.

7 Comments

Can you try to change the port: 8080 to some other port that you are sure is it not in use already, something like 8097
It doesn't work too... The BrowserSync server is well started but not the NodeJS application... And I'd like to start both of them on the same port.
The only way to do that is by using the browserSync proxy setting. I have updated the example so you can try. (Remember to change the paths to match your app)
Works better but Error: task completion callback called too many times
See edit #1. I found something to resolve my issue ;)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.