# gulp-express

> gulp livereload plugin

Latest version **0.3.5** (published 2015-03-24) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install gulp-express
pnpm add gulp-express
yarn add gulp-express
bun add gulp-express
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2015-03-24 |
| First published | 2014-07-17 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 56 |
| Author | yucc2008@gmail.com |
| Maintainers | yucc2008 |
| Keywords | gulpplugin, livereload, server, express |

## Links

- npm: https://www.npmjs.com/package/gulp-express
- Repository: https://github.com/gimm/gulp-express
- Issues: https://github.com/gimm/gulp-express/issues
- npm.io page: https://npm.io/package/gulp-express

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ^1.0.0
- [debug](https://npm.io/package/debug.md) ^2.1.1
- [tiny-lr](https://npm.io/package/tiny-lr.md) 0.0.9
- [deepmerge](https://npm.io/package/deepmerge.md) ~0.2.7
- [event-stream](https://npm.io/package/event-stream.md) ~3.2.1

## Recent versions

- 0.3.5 (latest) — 2015-03-24
- 0.3.4 — 2015-03-19
- 0.3.3 — 2015-03-18
- 0.3.2 — 2015-03-12
- 0.3.1 — 2015-03-12
- 0.3.0 — 2015-03-08
- 0.2.1 — 2015-03-05
- 0.2.0 — 2015-03-05
- 0.1.13 — 2015-02-20
- 0.1.12 — 2015-02-20
- 0.1.11 — 2015-02-20
- 0.1.10 — 2015-02-19
- 0.1.9 — 2015-02-18
- 0.1.8 — 2015-02-16
- 0.1.7 — 2015-01-21
- … 15 more at https://npm.io/package/gulp-express/versions

## README

please use [gulp-live-server](https://github.com/gimm/gulp-live-server) instead, it's a new version of `gulp-express` with a better name and new features.
===

[![Build Status][1]][2] [![Livereload downloads][3]][4] [![Tag][9]][8] [![MIT Licensed][5]](http://www.wtfpl.net/)

[1]: http://img.shields.io/travis/gimm/gulp-express/master.svg
[2]: https://travis-ci.org/gimm/gulp-express

[3]: http://img.shields.io/npm/dm/gulp-express.svg
[4]: https://www.npmjs.com/package/gulp-express

[5]: http://img.shields.io/badge/license-WTFPL-blue.svg

[8]: https://github.com/gimm/gulp-express/releases
[9]: https://img.shields.io/github/tag/gimm/gulp-express.svg

A gulp plugin which serve the app with livereload, internally, it does the following:
 * use [`ChildProcess.spawn`](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) to start a node process;
 * use [`tiny-lr`](https://github.com/mklabs/tiny-lr) provide livereload ability;

## Install
[![NPM](https://nodei.co/npm/gulp-express.png?compact=true)](https://nodei.co/npm/gulp-express/)

## Update notice
* v0.3.0

    > change signature of `server.run`. the third param `livereload` is used to config tiny-lr server.

* v0.2.0

    > get `console.log` back.

* v0.1.12

    > `options.lr` is used for creating tiny-lr server.  `options` here is the second parameter for [server.run](#serverrunargsoptions).

* v0.1.7
    > change signature for [server.run](#serverrunargsoptions), split `options`  into `args` and `options`.

* v0.1.5
    > pipe support added for [server.notify](#servernotifyevent)


## API

### server.run([args][,options][,livereload])
Run/re-run the script file, which will create a http(s) server.

Start a livereload(tiny-lr) server if it's not started yet.

Use the same arguments with [ChildProcess.spawn](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) with 'node' as command.

* `args` - `Array` - Array List of string arguments. The default value is `['app.js']`.
* `options` - `Object` - The third parameter for [ChildProcess.spawn](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options), the default value is:
```js
options = {
    cwd: undefined
}
options.env = process.env;
options.env.NODE_ENV = 'development';
```
* `livereload` - `Boolean|Number|Object` - The option for tiny-lr server. The default value is `35729`.
    * `false` - will disable tiny-lr livereload server.
    * `number` - treated as port number of livereload server.
    *  `object` - used to create tiny-lr server `new tinylr.Server(livereload);`.
* Returns a [ChildProcess](http://nodejs.org/api/child_process.html#child_process_class_childprocess) instance of spawned server.

### server.stop()
Stop the instantiated spawned server programmatically, and the tiny-lr server.

### server.notify([event])
Send a notification to the tiny-lr server in order to trigger a reload on page.
pipe support is added after v0.1.5, so you can also do this:
```js
gulp.src('css/*.css')
// …
.pipe(gulp.dest('public/css/'))
.pipe(server.notify())
```
* `event` (required when server.notify is invoked without pipe) - `Object` - Event object that is normally passed to [gulp.watch](https://github.com/gulpjs/gulp/blob/master/docs/API.md#cbevent) callback.
Should contain `path` property with changed file path.

## Usage

```js
// gulpfile.js
var gulp = require('gulp');
var server = require('gulp-express');

gulp.task('server', function () {
    // Start the server at the beginning of the task
    server.run(['app.js']);

    // Restart the server when file changes
    gulp.watch(['app/**/*.html'], server.notify);
    gulp.watch(['app/styles/**/*.scss'], ['styles:scss']);
    //gulp.watch(['{.tmp,app}/styles/**/*.css'], ['styles:css', server.notify]);
    //Event object won't pass down to gulp.watch's callback if there's more than one of them.
    //So the correct way to use server.notify is as following:
    gulp.watch(['{.tmp,app}/styles/**/*.css'], function(event){
        gulp.run('styles:css');
        server.notify(event);
        //pipe support is added for server.notify since v0.1.5,
        //see https://github.com/gimm/gulp-express#servernotifyevent
    });

    gulp.watch(['app/scripts/**/*.js'], ['jshint']);
    gulp.watch(['app/images/**/*'], server.notify);
    gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);
});
```
```js
// app.js
var express = require('express');
var app = module.exports.app = exports.app = express();

//you won't need 'connect-livereload' if you have livereload plugin for your browser
app.use(require('connect-livereload')());
```

---
_Source: https://npm.io/package/gulp-express · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
