Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure port in browser-sync

I have a gulp task running with browser-sync,by default its running on port 3000 of node.js server.I want to change the default port to any other port like 3010.

    var gulp = require('gulp'), 
    connect = require('gulp-connect'),          
    browserSync = require('browser-sync');    

    gulp.task('serve', [], function() {
    browserSync(
      {
        server: "../ProviderPortal"
       });
   });
   /*** 8. GULP TASKS **********/
   gulp.task('default', ['serve']);

I am using:

browser-sync version-2.6.1

I tried configuring the gulp task like:

gulp.task('serve', [], function() {
    browserSync(
    {
        ui: {
       port: 8080
       },
        server: "../ProviderPortal"
    });
});

But it didnot work.

like image 532
Gyanesh Gouraw Avatar asked Jun 03 '15 08:06

Gyanesh Gouraw


People also ask

How do I turn off browser sync?

You can prevent Browsersync from injecting the connection snippet by passing snippet: false .

How do I sync my browser with Sublime Text 3?

In Sublime Text 3 go to Preferences -> Browse Packages... Open 'Browser Sync' folder and edit the browser property in browser_sync_launch. js file. Show activity on this post.

What is browser sync Nodejs?

Browsersync is a tool that allows for live file watching and browser reloading. It's available as a NPM package.


1 Answers

Answer based on the documentation links (link1, link2).

You are using browser-sync version 2.0+, they have a different recommended syntax. Using that syntax your code could be like this:

// require the module as normal
var bs = require("browser-sync").create();

....

gulp.task('serve', [], function() {
  // .init starts the server
  bs.init({
    server: "./app",
    port: 3010
  });
});

You specify required port directly in configuration object.

like image 106
zaynetro Avatar answered Oct 04 '22 08:10

zaynetro