Installation
anarchon needs Node.js 20 or newer.
Install anarchon and the driver for your store. Drivers are optional peer dependencies, so you only install the one you use.
pnpm add anarchon redisWorks with Redis 5 or newer and with Valkey. redis (node-redis) is only needed if anarchon opens the
connection for you. You can pass a client your app already has instead: ioredis, iovalkey,
node-redis or Valkey GLIDE.
pnpm add anarchon pgPostgreSQL 9.5 or newer. You can pass your own pg Pool or Client, or a postgres.js
instance, instead of a connection string.
pnpm add anarchonNothing else is needed on Node 22.13 or newer, which has node:sqlite built in. Node 22.5 to
22.12 need the --experimental-sqlite flag. On Node 20 add better-sqlite3@12: version 13
needs Node 22. For a libSQL server or Turso add @libsql/client.
SQLite 3.35 or newer.
pnpm add anarchon amqplibRabbitMQ 3.9 or newer.
pnpm add anarchon @nats-io/transport-node @nats-io/jetstreamJetStream must be enabled on the server.
npm install and yarn add work the same way.
Which store should I pick?
Section titled “Which store should I pick?”Use the one your service already has. If you have a choice:
| You have | Use | Why |
|---|---|---|
| Redis or Valkey | The default, lease strategy |
The full feature set, and the least latency |
| PostgreSQL, no Redis | PostgresBackend |
The full feature set, with no new infrastructure |
| One machine, several processes | SqliteBackend on a file |
No server at all |
| Only RabbitMQ or NATS | RabbitMQBackend / NatsBackend |
One winner per run, but no backups, overlap protection or catch-up |
Backends overview compares them in detail.
TypeScript
Section titled “TypeScript”anarchon is written in TypeScript and ships its own types. There is nothing extra to install.
import { Scheduler, type JobContext, type RunRecord } from 'anarchon';It also works from plain JavaScript, with require or import:
const { Scheduler } = require('anarchon');Check that it works
Section titled “Check that it works”Save this as check.mjs and run node check.mjs. It uses a SQLite file, so it needs no server (Node 22.13 or newer).
import { Scheduler, SqliteBackend } from 'anarchon';
const scheduler = new Scheduler({ backend: new SqliteBackend({ database: './anarchon.db' }) });scheduler.every('hello', '2s', (ctx) => console.log('hello at', ctx.scheduledAt.toISOString()));
await scheduler.start();setTimeout(() => scheduler.stop(), 7_000);You should see a line every two seconds, then the process exits.
Quick start builds a small scheduler and runs it as three instances.