# rldr

> reloads a webpage on changes

Latest version **3.0.12** (published 2022-08-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install rldr
pnpm add rldr
yarn add rldr
bun add rldr
```

Provides the command `rldr`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.12 |
| Published | 2022-08-30 |
| First published | 2018-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | benjaminjackman |

## Links

- npm: https://www.npmjs.com/package/rldr
- npm.io page: https://npm.io/package/rldr

## Dependencies (2)

- [watch](https://npm.io/package/watch.md) ^1.0.2
- [express-longpoll](https://npm.io/package/express-longpoll.md) 0.0.4

## Recent versions

- 3.0.12 (latest) — 2022-08-30
- 3.0.11 — 2020-12-14
- 3.0.10 — 2020-12-14
- 3.0.9 — 2019-11-02
- 3.0.8 — 2019-11-02
- 3.0.7 — 2019-11-02
- 3.0.6 — 2019-11-02
- 3.0.5 — 2019-11-02
- 3.0.4 — 2019-11-02
- 3.0.3 — 2019-11-02
- 3.0.2 — 2019-01-19
- 3.0.1 — 2018-03-31
- 3.0.0 — 2018-03-03
- 2.0.3 — 2018-02-18
- 2.0.2 — 2018-02-18
- … 8 more at https://npm.io/package/rldr/versions

## README

rldr
----
Reloader, watches files for changes, reloads webpages in response

## step 1 add a script tag for rldr to your html
```
<script src="/rldr"></script>
```

## Option A: rldr in express
To use add this to your html someplace

Then in your express server add rldr to the app
### automatic watching
```
  const path = require("path")
  const pathsToWatch = [path.join(__pathname, "../src")] 
  require("rldr")(app, pathsToWatch)
```

### manual watching
```
  const path = require("path")
  reloadDirs = [path.join(__pathname, "../src")] 

  function addRldr(app) {
    const rldr = require("rldr")(app)
    const watch = require("watch")
  
    reloadDirs.forEach(dir => {
      watch.watchTree(dir, {interval: .2}, function (f, curr, prev) {
          console.log("Server Change Detected, reloading client")
          // Fire server-side reload event
          rldr.reload();
      });
    })
  }
```

## Option B: rldr as a command

this had been moved to a separate module named `rldr-cli`
[rldr-cli](https://www.npmjs.com/package/rldr-cli)


## Adding a custom origin for RLDR requests

If rldr is used in addition to another webserver, you may need to set
the RLDR_ORIGIN. So if you are loading rldr as 
`http://localhost:8045`
you can preset the variable with an inline script tag
```
<script>var RLDR_ORIGIN="http://localhost:8045"</script>
<script src="http://localhost:8045/rldr"></script>
```

or by settings `RLDR_ORIGIN` in localStorage

you will also probaby need to call the rldr-cli with
--alow-origin http://localhost:YOUR_OTHER_PORT

## Additional Notes

it uses `express-longpoll` to send reload events back to the client

## Questions

why not websockets? simplicity. longpoll just works in more environments.

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