How do you close old instances of BrowserSync when stopping Gulp in Terminal?
Asked Answered
E

1

5

I'm new to Gulp and BrowserSync, so I've been running gulp and stopping (forced by ctrl + z in terminal) it many times. Every time I start gulp again in terminal, BrowserSync gives me a new PORT number.

I need help removing the old instances of BrowserSync. Is there a command in terminal where I can view and delete old BS instances? Is this even possible? I started BS at port 3001 (Local) and 3002 (UI) and now I'm at 3018! I want to go back to 3001.

Also, how can I fix my Gulpfile.js code so when I force stop gulp in terminal, browserSync exits Local and UI server instances, so the port number doesn't keep increasing?

My BrowserSync portion in Gulpfile.js is very basic:

gulp.task('browser', function () {
  // Serve files from root of this folder
  browserSync({
      server: {
        baseDir: './'
      }
  });
  gulp.watch(['html/*.html', 'js/*.js']).on("change", reload);
});

gulp.task('default', ['styles','browser'], function() {
  gulp.watch('./sass/**/*.scss', ['styles']);
});

In my mac Terminal, the latest BS instance is at 30018, and UI happens to be at 3021 (because I recently used bs.server.close(), which closes Local instance, but not the UI instance.

[BS] Access URLs:
 --------------------------------------
       Local: http://localhost:3018
    External: http://192.168.1.164:3018
 --------------------------------------
          UI: http://localhost:3021
 UI External: http://192.168.1.164:3021
 --------------------------------------
[BS] Serving files from: ./
^Z
[16]+  Stopped                 gulp
Expecting answered 27/6, 2016 at 17:8 Comment(0)
M
9

The issue is ctrl + z only suspends the process. (see https://superuser.com/a/262948)

What you want is ctrl + c, which will kill it.

First, close your terminal, this should kill any port connections still active in the background.

Next, restart your server, but use ctrl + c to exit. You should be able to stop and restart continuously using this method.

Mizuki answered 27/6, 2016 at 20:16 Comment(1)
Thanks SteamDev! That did reset the server and BS's port numbers. I thought I had exited and closed out terminal before, but maybe not all the way. So, this time I typed "exit" (twice) then closed out Terminal and reopened it and ran "gulp" on my directory and it worked! Thanks a lot! I'll use ctrl + c next time to kill the whole process.Expecting

© 2022 - 2024 — McMap. All rights reserved.