JSPM

  • Created
  • Published
  • Downloads 38
  • Score
    100M100P100Q53221F
  • License AGPL-3.0-only

✚ Easily persist your own Page View Counter for free (no VPS or database plans required).

Package Exports

  • countty
  • countty/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (countty) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Countty ✚

Easily persist your own Page View Counter for free.



🧪 Quick Test Locally

You can test it locally, even if you don't have a Cloudflare account.

📦 Install

npm i countty

⛅️ Worker

Create the files:

  • index.js
import { createCountty } from 'countty';

const { Worker, Countty } = createCountty();

// Worker Routes
export default Worker;

// Durable Object (SQLite)
export { Countty };
  • wrangler.json
{
  "main": "index.js",
  "compatibility_date": "2025-09-24",
  "compatibility_flags": ["nodejs_compat"],
  "durable_objects": {
    "bindings": [
      {
        "name": "countty",
        "class_name": "Countty"
      }
    ]
  },
  "migrations": [
    {
      "tag": "v1",
      "new_sqlite_classes": ["Countty"]
    }
  ]
}

🏁 Run

npx -y wrangler dev

Example:

You can also install wrangler as a development dependency:

npm i -D wrangler

🔗 API Routes

[!IMPORTANT]

By default, the token for private routes is "123456". To change it, follow the steps in the next section.

  • /create: private
fetch('http://localhost:8787/create?slug=test', {
  headers: {
    Authorization: 'Bearer 123456',
  },
})
  .then((res) => res.json())
  .then(console.log);
  • /views: public
fetch('http://localhost:8787/views?slug=test')
  .then((res) => res.json())
  .then(console.log);
  • /backup: private
fetch('/backup', {
  headers: {
    Authorization: 'Bearer 123456',
  },
})
  .then((res) => res.text())
  .then(console.log);

🔐 Production Usage

For production use, you will need a Cloudflare account to proceed.

⛅️ Create your worker

npx wrangler deploy

🔑 Personalize your Token

To use in production, please create your personal token:

npx wrangler secret put TOKEN # Then press `Enter` to insert your token

[!TIP]

Create an .env file with the TOKEN variable to use the same token locally.

🐬 SQL Options

You can change the table name by specifying the name when creating Countty:

import { createCountty } from 'countty';

const { Worker, Countty } = createCountty({ table: 'my-table' });

// Worker Routes
export default worker;

// Durable Object (SQLite)
export { Countty };

⚖️ Restrictions on the free plan: