Skip to content

Commit 8f69358

Browse files
committed
Update readme with info about sse and cli
1 parent 57edbd2 commit 8f69358

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,52 @@ If you just want to get the views for an id and don't want to increment the view
5050

5151
If you want to get all views for all ids, set the `all` query parameter to `true` on a root request. (i.e. `/?all=true`) If you pass the `all` parameter to an id, all ids starting with that pathname will be included. E.g. `/x?all=true` will match views for `/x`, `/xyz` but not `/y`.
5252

53+
### Options
54+
55+
```
56+
$ micro-analytics --help
57+
Usage: micro-analytics [options] [command]
58+
59+
Commands:
60+
61+
help Display help
62+
63+
Options:
64+
65+
-a, --adapter [value] Database adapter used (defaults to "flat-file-db")
66+
-h, --help Output usage information
67+
-H, --host [value] Host to listen on (defaults to "0.0.0.0")
68+
-p, --port <n> Port to listen on (defaults to 3000)
69+
-v, --version Output the version number
70+
```
71+
5372
### Database adapters
5473

5574
By default, `micro-analytics` uses `flat-file-db`, a fast in-process flat file database, which makes for easy setup and backups.
5675

57-
This works fine for side-project usage, but for a production application with bajillions of visitors you might want to use a real database with a _database adapter_. Install the necessary npm package (e.g. `micro-analytics-adapter-xyz`) and then specify the `DB_ADAPTER` environment variable: `$ DB_ADAPTER=xyz micro-analytics`
76+
This works fine for side-project usage, but for a production application with bajillions of visitors you might want to use a real database with a _database adapter_. Install the necessary npm package (e.g. `micro-analytics-adapter-xyz`) and then specify the `DB_ADAPTER` environment variable: `$ DB_ADAPTER=xyz micro-analytics` or use the `--adapter` cli option.
5877

5978
These are the available database adapters, made by the community:
6079

6180
- [`micro-analytics-adapter-redis`](https://github.com/relekang/micro-analytics-adapter-redis)
6281

6382
Don't see your favorite database here? Writing your own adapter is super easy! See [`writing-adapters.md`](writing-adapters.md) for a simple step-by-step guide.
6483

84+
### Live updates
85+
86+
micro-analytics has support for live updates with [server-sent events][]. This is an optional feature
87+
in the adapter backend so check that your chosen backend has the support for it. Below is a little
88+
example on how to listen for the events.
89+
90+
```es6
91+
const sse = new EventSource('/sse')
92+
sse.onopen = function () { console.log('[sse] open') }
93+
sse.onerror = function (error) { console.error('[sse error]', error) }
94+
sse.addEventListener('new-event', function (e) { console.log('[sse]', e) })
95+
```
96+
97+
[server-sent events]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
98+
6599
## License
66100

67101
Copyright ©️ 2017 Maximilian Stoiber, licensed under the MIT License. See [`license.md`](./license.md) for more information.

0 commit comments

Comments
 (0)