Skip to content

Commit d7c10a9

Browse files
committed
Add documentation for CLI
1 parent 005608b commit d7c10a9

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ A tiny analytics server with less than 100 lines of code, easy to run and hack a
1010

1111
## Setup
1212

13-
1. `git clone [email protected]:mxstbr/micro-analytics` to get the repo.
14-
2. `npm install` to install the dependencies.
15-
3. `npm start` to start the service.
13+
```
14+
npm install -g micro-analytics-cli
15+
micro-analytics
16+
```
17+
18+
And that's it! 🎉 The analytics server is now running at `localhost:3000`. (see [`server-setup.md`](./server-setup.md) for instructions on acquiring a server and setting up `nginx` to make this publicly available)
1619

17-
And that's it! 🎉 (see [`deployment.md`](./deployment.md) for deployment instructions)
20+
> **Note**: You can pass any option to the `micro-analytics` command that you can pass to [`micro`](https://github.com/zeit/micro). As an example, to change the host you'd do `micro-analytics -H 127.0.0.1`
1821
1922
## Usage
2023

2124
### Tracking views
2225

23-
To track a view, simply send a request to `/<yourpath>`. If you send a `GET` request, the request will increment the views and return the total views. If you send a `POST` request, the views will increment but you don't get the total views back.
26+
To track a view, simply send a request to `/<id>`. If you send a `GET` request, the request will increment the views and return the total views for that id. If you send a `POST` request, the views will increment but you don't get the total views back.
2427

2528
This is how you'd track pageviews for a website: (though note that this can be used to track anything you want)
2629

@@ -34,13 +37,9 @@ This is how you'd track pageviews for a website: (though note that this can be u
3437
</script>
3538
```
3639

37-
If you just want to get the views for a path and don't want to increment the views during a `GET` request, set `inc` to `false` in your query parameter. (`/<yourpath>?inc=false`)
38-
39-
If you want to get all views for all paths, set the `all` query parameter to `true`. (`/?all=true`)
40-
41-
## Contributing
40+
If you just want to get the views for an id and don't want to increment the views during a `GET` request, set `inc` to `false` in your query parameter. (`/<id>?inc=false`)
4241

43-
If you run `npm run dev` the server will restart every time you edit the code. Perfect for development of `micro-analytics`!
42+
If you want to get all views for all ids, set the `all` query parameter to `true`. (`/?all=true`)
4443

4544
## Built with
4645

contributing.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributing
2+
3+
## Local setup
4+
5+
1. Clone the repository with `git clone [email protected]:mxstbr/micro-analytics.git`
6+
2. Install the dependencies with `npm install` (or `yarn install` if you have `yarn`)
7+
3. Run the server in dev mode with `npm run dev`, which will restart the server everytime you edit the code.

deployment.md renamed to server-setup.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
# Deployment
1+
# Server Setup
22

3-
Deploying this service is a short three step process. This assumes you already have a server with an OS of your choice that runs Node setup, if not refer to the [acquire a server](#acquire-a-server) section.
3+
Running `micro-analytics` on a server is a simple two step process:
44

5-
1. Upload the files of the service to your server (you should be able to do this on your own)
6-
2. Start and daemonize the app with `pm2`
7-
3. Setup `nginx` as a reverse proxy to make your service publicy accessible
5+
1. Start and daemonize the app with `pm2`
6+
2. Setup `nginx` as a reverse proxy to make your service publicy accessible
7+
8+
## Prerequisite: A server
9+
10+
If you don't have a server to run this on yet, here is what I do:
11+
12+
I use and like [DigitalOcean](https://m.do.co/c/d371ed7f99af) (referral link) for my servers. A simple, 5$/month droplet will suffice to run this service reliably. (upgrading to more power in case of big traffic is two clicks away too)
13+
14+
Make sure to choose the `NodeJS x.x.x on 16.04` (where `x.x.x` is the highest version number you can find) one-click app when creating the droplet to get the server fully setup with Node and Ubuntu.
815

916
## Start and deamonize the app
1017

11-
Once all the files for this microservice are uploaded we'll use `pm2` to start and deamonize the app. This means that the app isn't bound to the terminal, and we'll also make `pm2` start the app when the server start.
18+
Install `micro-analytics` on your server by running `npm install -g micro-analytics-cli` in its shell.
19+
20+
We'll use `pm2` to start and deamonize the app. This means that the app isn't bound to the terminal, and we'll also make `pm2` start the app when the server start. (this avoids the service being down in case your server reboots)
1221

13-
First run `npm install -g pm2` to get `pm2`, then run `pm2 start npm -- start`. This tells `pm2` to run `npm start` in the background.
22+
First run `npm install -g pm2` to get `pm2`, then run `pm2 start micro-analytics`. This tells `pm2` to run `micro-analytics` in the background.
1423

1524
To make sure our service stays up even if the server reboots we run `pm2 startup ubuntu` (replace `ubuntu` with whatever OS you're using) and `pm2 save`.
1625

1726
## Set up `nginx`
1827

19-
Get `nginx` by running `sudo apt-get install nginx`, then configure it to reroute all incoming requests to the server to our server.
28+
Get `nginx` by running `sudo apt-get install nginx`, then configure it to reroute all incoming requests to the server to `micro-analytics`.
2029

2130
Delete the default site from nginx by running `sudo rm /etc/nginx/sites-enabled/default`, then create a new one by running `sudo touch /etc/nginx/sites-enabled/<yoursite>`. (replace `<yoursite>` with your site name)
2231

23-
We want to reroute all requests for any path that come in to our service, so edit the `/etc/nginx/sites-enabled/<yoursite>` file to look like this:
32+
We want to reroute all requests for any path that come in to `localhost:3000` (where `micro-analytics` is running), so edit the `/etc/nginx/sites-enabled/<yoursite>` file to look like this:
2433

2534
```nginx
2635
server {
@@ -37,11 +46,3 @@ server {
3746
```
3847

3948
(note that I have no idea what I'm doing here, this was copied from [this tutorial](https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-for-apache))
40-
41-
## Acquire a server
42-
43-
If you don't have a server to deploy this on just yet, here is what I do:
44-
45-
I use and like [DigitalOcean](https://m.do.co/c/d371ed7f99af) (referral link) for my servers. A simple, 5$/month droplet will suffice to run this service reliably. (upgrading to more power in case of big traffic is two clicks away too)
46-
47-
Make sure to choose the `NodeJS x.x.x on 16.04` (where `x.x.x` is the highest version number you can find) one-click app when creating the droplet to get the server fully setup with Node and Ubuntu.

0 commit comments

Comments
 (0)