npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@waves-counter/node

v0.2.2

Published

Native Node and Express integration for Wave Counter

Readme

@waves-counter/node

Native Node and Express integration for Wave Counter.

This package wraps the shared Rust engine with a Node API and an optional Express router. It stores anonymous counter events in SQLite, handles idempotent event IDs, and keeps database work off the JavaScript event loop.

Install

npm install @waves-counter/node express

Node 20 or newer is required.

Quick start with Express

import express from 'express'
import { WaveCounter } from '@waves-counter/node'
import { createWaveRouter } from '@waves-counter/node/express'

const app = express()
const counter = new WaveCounter({
  databasePath: process.env.WAVE_COUNTER_DB ?? './wave-counter.sqlite3',
  initialCounts: { coffee: 67 },
  busyTimeoutMs: 1000,
})

app.use(express.json())
app.use(
  '/api/waves',
  createWaveRouter(counter, {
    authorize: (request) => request.header('x-api-key') === process.env.WAVE_COUNTER_API_KEY,
  }),
)

app.listen(3000)

The router exposes:

GET  /counters/{key}
POST /counters/{key}/events
GET  /counters/{key}/analytics?window=7d|1M|all

Direct API

import { WaveCounter } from '@waves-counter/node'

const counter = new WaveCounter({
  databasePath: './app.sqlite3',
  initialCounts: { coffee: 67 },
})

const before = await counter.getCounter('coffee')

const result = await counter.recordEvent(
  'coffee',
  '0198f2f7-6d42-7d94-b1a6-e4305543f132',
)

const analytics = await counter.analytics('coffee', '7d')

counter.close()

recordEvent returns { counter, created }. Reusing the same event ID returns created: false and does not increment again.

Call close() when you need deterministic teardown, such as tests or short-lived scripts that delete the SQLite file immediately afterward. Long-running servers can let process shutdown release the engine naturally.

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | databasePath | string | ./wave-counter.sqlite3 | SQLite database file. | | initialCounts | Record<string, number> | {} | Baseline totals inserted once for new counters. | | busyTimeoutMs | number | Engine default | SQLite busy timeout before returning a retryable busy error. |

Error handling

Storage and validation failures throw WaveCounterError:

try {
  await counter.recordEvent('coffee', eventId)
} catch (error) {
  if (error instanceof WaveCounterError && error.code === 'busy') {
    // Retry later.
  }
}

The Express router maps invalid counter keys, event IDs, and analytics windows to 400; storage pressure to 503 with Retry-After: 1; and authorization failures to 403.

Operations

  • The engine creates only waves_* tables in the supplied SQLite database.
  • WAL mode and foreign keys are enabled by the engine.
  • Analytics include real events only. Imported baselines do not fabricate history.
  • Hosts own authentication, CORS, rate limiting, backups, and durable volume configuration.
  • Keep the database on persistent storage in production deployments.

Frontend packages