I am having issues creating a nodemon + browserSync via gulp task. I have searched online for a possible solution. I looked on StackOverflow site, but I still have not found any success to a solution for my issue. I am running into this issue
events.js:167
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
I am not sure why when I execute gulp
in command line I get this error EADDRINUSE :::3000
. I have checked the port using netstat -ano | findStr "9000"
netstat -ano | findStr "9000"
the port isn't being called by another process. I am not sure why I run into this issue when I execute my gulp task. Can someone please provide some guidance? I will greatly appreciate I am running out of options.
gulpfile.js
gulp.task('nodemon', function (cb) {
var called = false;
return nodemon({
script: './server.js',
ignore: [
'../server/gulpfile',
'../server/server.js',
'../server/node_modules/'
],
}).on('start', function () {
if (!called) {
cb();
called = true;
}
}).on('restart', function () {
setTimeout(function () {
reload({ stream: false });
}, 1000);
});
});
gulp.task('browser-sync', ['nodemon'], function() {
browserSync.init({
proxy: 'http://localhost:9000',
open: false,
browser:'google-chrome',
port: 9000,
notify: true
});
});
// Static Server + watching scss/hbs files
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "./client"
});
gulp.watch(['node_modules/**/*.scss', '../client/**/*.scss'], ['sass']);
gulp.watch("client/views/partials/*.hbs").on('change', browserSync.reload);
});
gulp.task('default', ['js','serve', 'browser-sync']);
folder Structure folder structure image
earlier I had posted about an error I was running into using nodemon and browserSync together. I finally figured out the issue I was having. The reason I was getting EARDINUSE3000 error was because I was calling browerSync twice within my gulpfile.js The solution to my issue was this.
gulp.task('nodemon', function (cb) {
var called = false;
return nodemon({
script: './server.js',
ignore: [
'../server/gulpfile',
'../server/server.js',
'../server/node_modules/'
],
}).on('start', function () {
if (!called) {
cb();
called = true;
}
}).on('restart', function () {
setTimeout(function () {
reload({ stream: false });
}, 1000);
});
});
gulp.task('browser-sync', ['nodemon'], function() {
browserSync.init({
proxy: 'http://localhost:3000',
open: false,
browser:'google-chrome',
port: 4000,
baseDir: 'build',
notify: true,
});
gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', '../client/**/*.scss'],
['sass']);
gulp.watch('client/**/*.hbs').on('change', browserSync.reload);
});
gulp.task('default', ['js', 'browser-sync']);
For anyone running into this issue in the future I hope this is helpful.
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.