A persistent and robust visitor counter for web pages.
- Persistent storage - Uses SQLite database to persist visitor counts across restarts
- Atomic operations - Uses database transactions to prevent race conditions
- Visit logging - Records IP addresses and timestamps for analytics
- Embeddable badge - SVG badge you can embed in READMEs or other pages
- Graceful shutdown - Properly closes database connections on shutdown
- Request logging - Logs all requests with timing information
# Install dependencies
npm install
# Start the server
npm start
# Or run in development mode with auto-reload
npm run devThe server runs on port 3000 by default. Open http://localhost:3000 to see the counter.
| Endpoint | Method | Description |
|---|---|---|
/api/visit |
GET | Increment counter and return new value |
/api/count |
GET | Get current count without incrementing |
/api/count |
POST | Increment counter |
/api/stats |
GET | Get visitor statistics |
/api/badge |
GET | Get SVG badge image |
/health |
GET | Health check endpoint |
Environment variables:
| Variable | Default | Description |
|---|---|---|
PORT |
3000 | Server port |
COUNTER_NAME |
default | Name of the counter (for multiple counters) |
LOG_LEVEL |
info | Logging level (error, warn, info, debug) |
Add this to your README or HTML:
<img src="https://your-domain.com/api/badge" alt="Visitors">Data is stored in data/visitors.db (SQLite). The database uses WAL mode for better concurrent performance.
To backup your data, copy the data/ directory.
MIT