Browser-sync: Add an option to disable automatic port selection

Created on 11 May 2016  路  2Comments  路  Source: BrowserSync/browser-sync

Issue details

If you're manually adding the script to your layout file, the port is fixed (at, for example, 3000), but if that port is in use, Browsersync will pick another port and the website will fail to connect.

We cannot update the layout file every time that the port changes, so it makes sense to configure Browsersync to fail if the port is in use.

Would you consider adding an option that causes a failure if the port is in use?

Steps to reproduce/test case

n/a

Please specify which version of Browsersync, node and npm you're running

  • Browsersync [ 2.12.5 ]
  • Node [ 5.11.0 ]
  • Npm [ 3.8.6 ]

    Affected platforms

  • [x] linux

  • [x] windows
  • [x] OS X
  • [x] freebsd
  • [x] solaris
  • [ ] other _(please specify which)_

    Browsersync use-case

  • [x] API

  • [x] Gulp
  • [x] Grunt
  • [x] CLI

    If CLI, please paste the entire command below

n/a

for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync

n/a

V3

Most helpful comment

V3 has strict mode which will do exactly this, but for now you might consider using the following

var bs = require('browser-sync').create();

bs.init({
    server: './app',
    port: 9000
}, function (err, bs) {
    if (bs.options.get('port') !== 9000) {
        console.log('Port 9000 not available');
        process.exit(1);
    }
});

All 2 comments

V3 has strict mode which will do exactly this, but for now you might consider using the following

var bs = require('browser-sync').create();

bs.init({
    server: './app',
    port: 9000
}, function (err, bs) {
    if (bs.options.get('port') !== 9000) {
        console.log('Port 9000 not available');
        process.exit(1);
    }
});

Great, thanks Shane!

Shall we close this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielverejan picture danielverejan  路  3Comments

ericmorand picture ericmorand  路  3Comments

codeofsumit picture codeofsumit  路  3Comments

w88975 picture w88975  路  3Comments

zewa666 picture zewa666  路  3Comments