0

Before executing "var bs = browserSync.create();", I would like to kill browserSync if a browserSync process is running.

Is it correct that exit() method needs a browsersync instance? ( https://www.browsersync.io/docs/api#api-exit)

What is the best way ?

//A gulp script

var browserSync = require('browser-sync');

//Step 1 --- Kill browsersync

?

//Step2 --- Start browsersync

var bs = browserSync.create();
Mayu
  • 25
  • 5

1 Answers1

1

reference from the documentation

var bs = require("browser-sync").create();
console.log(bs.active); // will return true/false whether browserSync is running or not

if(bs.active) {
    bs.exit();
} else {
    bs.init(config, function (err, bs) {    
    // -> now true since BS is running now
    console.log(bs.active);
   });
}
xkeshav
  • 53,360
  • 44
  • 177
  • 245