Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 517
jussjosh Avatar asked Jan 06 '23 19:01

jussjosh


1 Answers

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.

like image 131
SteamDev Avatar answered Jan 08 '23 10:01

SteamDev