Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Last version Build Status Dependency status Dev Dependencies Status

A simple microservice for counting things.

It's inspired by and

Deploy with Vercel


You can count whatever you want.

Imagine you are visiting a blog post and you want to count views.

Just pass the blog post relative path for counting pageviews: → → HTTP 201 Created

The service will return you the current counter, and the first and last timestamp associated:

  "updatedAt": 1564327678670,
  "createdAt": 1564327676653,
  "count": 25

For counting thing, you need to perform a GET to, being supported the following query string:

  • increment|incr: When it is present, it specifies how much increment the value.

It doesn't matter if your id contains final slash; it will be sanitized.

For printing the value in your website, a representative code for doing that could be:

  fetch('' + window.location.pathname + '?increment&collection=pageviews)
    .then(res => res.json())
    .then(({ pageviews }) => {
      document.querySelector('.pageviews-count').textContent = pageviews

Environment Variables


The service is backed at Firebase. You need to create an account (it's free!) and copy some relevant values you can find in your Firebase accounts tab.


Type: string

The project id to use.


Type: string

Your private key associated with your Firebase account.

It should be encoded in base64.


Type: string

Your email associated with your Firebase account.


The following environment variables are optional and they are used protecting abusive use of the service from external traffic.


Type: string

When you provide it, all request to need to be authenticated in order to increment counters.

The API key can be provided:

  • as x-api-key request header.
  • as key or apiKey as query parameter.

You can use for generating an unique API key.


Type: string|string[]

The list of allowed domains that authorized to interact with the service.

Rate Limit

The following variables are optional and providing them enable a rate limit window associated per request IP address.


Type: number

It defines a rate limit window, where the value specified is the number of seconds before RATE_LIMIT_MAX points are reset.

The value should be expressed in milliseconds.


Type: number

It defines a rate limit window, where the value is the maximum number of points can be consumed over RATE_LIMIT_WINDOW.


count-microservice © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors. · GitHub Kiko Beats · Twitter @Kikobeats