Gulp plugin to run a local webserver with livereload enabled via


Gulp plugin to run a local webserver with live reload using

Serve a folder over HTTP and watch it for changes, telling the browser to reload itself when a change happens.

  • Uses - livereload mechanism works even if your browser does not support WebSockets (PhoneGap developers rejoice!).

  • window.console capture - it can capture console output from the client-side and transmit it to the back-end for display. This is useful for when testing from Phonegap, etc.

  • Comes with a command-line runnable.

This was originally a fork of gulp-webserver.

$ npm install --save-dev gulp-server-livereload

The folder supplied to gulp.src() will be the root folder from which files will be served.

var gulp = require('gulp');
var server = require('gulp-server-livereload');
gulp.task('webserver', function() {
      livereload: true,
      directoryListing: true,
      open: true

If you run gulp webserver your browser should automatically open up to http://localhost:8000 and show a directory listing of the app folder.

Install the package globally:

$ npm install -g gulp-server-livereload

Then you can run the livereload command to serve files out of the current folder. Here are the available options:

$ livereload help
  Usage: livereload [options]
    -h, --help        output usage information
    -V, --version     output the version number
    -n, --no-browser  do not open the localhost server in a browser
    -l, --log [type]  log level (default: info)
    -p, --port <n>    the port to run on

Note: not all of these options are currently available via the CLI executable

hostStringlocalhosthostname of the webserver
portNumber8000port of the webserver
livereloadBoolean/Objectfalsewhether to use livereload. For advanced options, provide an object. You can use the port property to set a custom live reload port (default is 35729) and the filter function to filter out files to watch (default filters out node_modules).
directoryListingBoolean/Objectfalsewhether to display a directory listing. For advanced options, provide an object. You can use the path property to set a custom path or theoptions` property to set custom serve-index options.
defaultFileStringindex.htmldefault file to show when root URL is requested. If directoryListing is enabled then this gets disabled.
openBoolean/Objectfalseopen the localhost server in the browser
httpsBoolean/Objectfalsewhether to use https or not. By default, gulp-server-livereload provides you with a development certificate but you remain free to specify a path for your key and certificate by providing an object like this one: {key: 'path/to/key.pem', cert: 'path/to/cert.pem'}.
logStringinfoIf set to debug you will see all requests logged to the console.
clientConsoleBooleanfalsewhether to capture window.console output from the client and send it to the back-end for display.

Set as the host option.

Set the defaultFile to main.html:

gulp.task('webserver', function() {
      defaultFile: 'main.html'

In the livereload object, set the enable to true and provide filter function in filter:

gulp.task('webserver', function() {
      livereload: {
        enable: true,
        filterfunction(filePathcb) {
          cb( !(/node_modules/.test(filePath)) );

MIT - see