# watch-connect

> A connect/express middleware that force browsers to reload when the server detects file changes.

Latest version **0.3.4** (published 2012-08-19) · 0 weekly downloads

## Install

```sh
npm install watch-connect
pnpm add watch-connect
yarn add watch-connect
bun add watch-connect
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2012-08-19 |
| First published | 2012-06-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Filirom1 |
| Maintainers | Filirom1, filirom1, dbashford |
| Keywords | live, reload, livereload, connect, express |

## Links

- npm: https://www.npmjs.com/package/watch-connect
- Repository: https://github.com/Filirom1/watch-connect
- npm.io page: https://npm.io/package/watch-connect

## Dependencies (2)

- [chokidar](https://npm.io/package/chokidar.md) ~0.4.0
- [socket.io](https://npm.io/package/socket.io.md) ~0.9.6

## Recent versions

- 0.3.4 (latest) — 2012-08-19
- 0.3.3 — 2012-08-13
- 0.3.2 — 2012-08-03
- 0.3.1 — 2012-07-29
- 0.3.0 — 2012-07-18
- 0.2.2 — 2012-07-12
- 0.2.1 — 2012-07-12
- 0.2.0 — 2012-06-21
- 0.1.0 — 2012-06-05

## README

# watch-connect

A connect/express middleware that force browsers to reload when the server detects file changes.

The watch mode has been borrowed from [https://github.com/mklabs/mockerie](mockerie) by the genious [mklabs](https://github.com/mklabs).

## Usage With Connect

    var Path = require('path'),
      connect = require('connect'),
      reloadOnChange = require('watch-connect');

    var path = Path.resolve('example/fixture');

    var server = connect();
    var options = {watchdir:path, server:server, verbose: true};
    server.use(reloadOnChange(options));
    server.use(connect.static(path));

    server.listen(3000, function(){
      console.log('listening on http://127.0.0.1:3000');
    });

Now open your browser on the URL `http://127.0.0.1:3000`.

Look at the title color.

Now change the color in `example/fixture/sub/folder/file.css`, and save your changes.

Oh look the browser was updated :)

## Usage With Express

TBD

## Options

 * `watchdir`: __Required__.  A path to the directory you want to watch, ideally the path to your public assets.  .html files inside this directory will have script tags inserted on their way through the connect middleware (unless `skipAdding` is set to `true`).  Those scripts facilitate the reload.
 * `server`: __Required__.  http server to hook our reload
 * `verbose`: Defaults to false.  Chatty logging.
 * `skipAdding`: Defaults to false.  When set to true, the socket scripts will not be added to .html pages on their way through the middleware.  The assumption is that you would add them to your page(s) yourself.  This serves as a workaround for those who are not rendering .html pages directly, like Express users who may be using Jade templates.
 * `exclude`: an array of _file regexs_ that when changed should not cause a reload.  By default, files containing `/.` (`like foo/.gitignore`) and `node_modules` will be ignored.
 * `additionaldirs`: an array of file paths to additional directories that you want to force a refresh of the browser.  No files inside this directory will not have the script tags inserted into them, these files simply trigger reloads.  Use this to, for example, watch your Jade templates, which typically live outside the directory structure of your public assets.

## License

(The MIT License)

Copyright (c) 2012 Filirom1

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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