Error: listen EADDRINUSE 127.0.0.1:3000

Asked By: Anonymous

I use the following example to setup an express server: https://github.com/sogko/gulp-recipes/tree/master/browser-sync-nodemon-expressjs .

I use gulp to kickstart several processes like minifying, vulcanizing and folding up my Polymer project.

The gulpfile.js is 364 lines big, but this is the part that matters:

// Build and serve the output from the dist build
appsPaths.forEach(function(app) {
  gulp.task('serve:dist:' + app,
    ['browser-sync', 'default:' + app]);
});

gulp.task('browser-sync', ['nodemon'], function () {

  // for more browser-sync config options: http://www.browsersync.io/docs/options/
  browserSync({
    notify: false,
    snippetOptions: {
      rule: {
        match: '<span id="browser-sync-binding"></span>',
        fn: function (snippet) {
          return snippet;
        }
      }
    },

    // informs browser-sync to proxy our expressjs app which would run at the following location
    proxy: 'http://localhost:3000',

    // informs browser-sync to use the following port for the proxied app
    // notice that the default port is 3000, which would clash with our expressjs
    port: 4000,

    // open the proxied app in chrome
    browser: ['google-chrome']
  });
});

gulp.task('nodemon', function (cb) {
  var called = false;
  return $.nodemon({

    // nodemon our expressjs server
    script: 'server/app.js',

    // watch core server file(s) that require server restart on change
    watch: ['server/app.js']
  })
    .on('start', function onStart() {
      // ensure start only got called once
      if (!called) { cb(); }
      called = true;
    })
    .on('restart', function onRestart() {
      // reload connected browsers after a slight delay
      setTimeout(function reload() {
        browserSync.reload({
          stream: false
        });
      }, BROWSER_SYNC_RELOAD_DELAY);
    });
});

Now while this works great and all I still get the following error ending up in my gulp log:

^CDaniels-iMac:polymer dani$ gulp serve:dist:domain.com
[22:33:10] Using gulpfile ~/dev/company/polymer/gulpfile.js
[22:33:10] Starting 'nodemon'...
[22:33:10] Starting 'clean:domain.com'...
[22:33:10] Finished 'clean:domain.com' after 8.56 ms
[22:33:10] Starting 'default:domain.com'...
[22:33:10] Starting 'copy:domain.com'...
[22:33:10] Starting 'styles:domain.com'...
[22:33:11] Finished 'styles:domain.com' after 295 ms
[22:33:11] [nodemon] 1.9.2
[22:33:11] [nodemon] to restart at any time, enter `rs`
[22:33:11] [nodemon] watching: server/app.js
[22:33:11] [nodemon] starting `node server/app.js`
[22:33:11] Finished 'nodemon' after 570 ms
[22:33:11] Starting 'browser-sync'...
[22:33:11] Finished 'browser-sync' after 20 ms
events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE 127.0.0.1:3000
    at Object.exports._errnoException (util.js:890:11)
    at exports._exceptionWithHostPort (util.js:913:20)
    at Server._listen2 (net.js:1234:14)
    at listen (net.js:1270:10)
    at net.js:1379:9
    at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:63:16)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:82:10)
[22:33:11] [nodemon] app crashed - waiting for file changes before starting...
[BS] Proxying: http://localhost:3000
[BS] Access URLs:
 ----------------------------------
       Local: http://localhost:4000
    External: http://10.0.1.28:4000
 ----------------------------------
          UI: http://localhost:3001
 UI External: http://10.0.1.28:3001
 ----------------------------------
[22:33:12] copy all files 16.03 MB
[22:33:12] Finished 'copy:domain.com' after 1.78 s
[22:33:12] Starting 'elements:domain.com'...
[22:33:12] Finished 'elements:domain.com' after 5.39 ms
[22:33:12] Starting 'jshint:domain.com'...
[22:33:12] Starting 'images:domain.com'...
[22:33:12] Starting 'fonts:domain.com'...
[22:33:12] Starting 'html:domain.com'...
[22:33:12] Finished 'images:domain.com' after 339 ms
[22:33:12] Finished 'fonts:domain.com' after 157 ms
[BS] Reloading Browsers...

This is what I see before and after triggering a run of the gulp script:

Daniels-iMac:polymer dani$ lsof -i tcp:3000
Daniels-iMac:polymer dani$
Daniels-iMac:polymer dani$ lsof -i tcp:3000
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    95580 dani   19u  IPv4 0x8560662b0408bad3      0t0  TCP localhost:hbci (LISTEN)

So it appears there’s not a lot going on on port 3000. What can I do to resolve this error?


Solution

Answered By: Anonymous

I think you’re running browserSync with the same ports several times on http://localhost:3000 due to the forEach, which I assume has several paths.

techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno