Deployment modes
memento is one Fastify plugin, mementoPlugin from @jsmemento/server. Where it runs is up to
you: inside an application you already have, as its own container, or not at all on your side —
on the hosted service, with a key. Where you run it, the database is PostgreSQL or a single
SQLite file (below).
| you run | you get | |
|---|---|---|
| Embedded | your Node app, your PostgreSQL or a SQLite file | memento’s routes under a prefix of your app, its memento_* tables in your database |
| Standalone | the image or @jsmemento/server; PostgreSQL (optionally Redis) or a SQLite file |
the server, the CLI, the examples site and the service site |
| Hosted | nothing | a tenant on the hosted service and keys for it |
Embedded
Section titled “Embedded”app.register(mementoPlugin, { prefix: "/memento", db, … }) in your own Fastify app. The plugin
is encapsulated: its error handler and its authentication hooks apply to its own routes only,
and your routes stay yours. Every table it creates is named memento_*, so it can share your
application’s database; runMigrations(db) applies its migrations.
import { connect, LocalBus, mementoPlugin, runMigrations } from "@jsmemento/server";import Fastify from "fastify";
// DATABASE_URL picks the database: file:<path> is one SQLite file, postgresql://… your// PostgreSQL, where memento's tables live next to yours, all named memento_*.const database = connect(process.env.DATABASE_URL ?? "file:data/app.db");await runMigrations(database.db); // on SQLite this creates the file on the first start
// One process: it publishes the events it stores and streams them to /ws itself.// More than one (PostgreSQL only): a RedisPublisher and a RedisFeed, so every process sees every event.const bus = new LocalBus();
const app = Fastify({ logger: true });app.get("/", async () => ({ hello: "your own routes stay yours" }));await app.register(mementoPlugin, { prefix: "/memento", db: database.db, publisher: bus, stream: { feed: bus },});app.addHook("onClose", async () => { await bus.close(); await database.close();});
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => void app.close());await app.listen({ port: Number(process.env.PORT ?? 8000) });The options of mementoPlugin:
| option | |
|---|---|
db |
the database, from connect(url): postgresql://… or file:<path> — the only required one |
publisher |
where stored events are published: a RedisPublisher with several processes (PostgreSQL), a LocalBus with one |
stream |
{ feed } enables /ws (heartbeatIntervalMs, maxBufferedMessages optional); without it there is no stream and /describe says realtime: false |
udc |
the UDC collections: memento’s own by default (events, cpu_load, activity), your own CollectionRegistry, or false for none |
menu |
a menu YAML served as the menu collection |
lookups, defaultLocale, renderer |
the vocabulary, the locale when a request names none (en), the template renderer |
demoApiKey |
a read-only key GET /api/demo hands out; anything but exactly read fails startup |
accounts |
self-service accounts (serviceUrl, mailer, limits); off by default |
If the host app already registered @fastify/websocket it is reused; register it before the
memento plugin. Embedded in Node walks through it, with a stream
client on the other end.
Standalone
Section titled “Standalone”One Docker image, ghcr.io/digital-cube/jsmemento, multi-arch (amd64, arm64), Node 24, running as
the unprivileged node user. Its entrypoint applies pending migrations, loads the lookups and
listens on port 3000; SIGTERM closes the WebSocket clients, Redis if there is one and the
database, then exits.
The image also carries:
/usr/local/bin/memento, the CLI, with the sameDATABASE_URLandREDIS_URLas the server;memento-healthcheck, the image’sHEALTHCHECK(GET /memento/api/health);/app/config/lookups.yamland the translations,/app/config/menu.yaml, and the built examples site (/app/ui) and service site (/app/ui-service);/data, a volume for the lookup candidates, and for the database file on SQLite (DATABASE_URL=file:/data/memento.db).
The repository’s docker-compose.yaml is the production-like stack on PostgreSQL:
| service | |
|---|---|
memento |
the server and the examples site, port 3000 |
postgres |
PostgreSQL 18, published on 127.0.0.1 only |
redis |
Redis 7, the same |
service |
the service site, a second container of the same image, port 8201 |
cpu-monitor, simulator, retention |
profile demo, off by default: the two pushers the examples site shows, and memento retention once a day |
The server is configured by environment variables only (Environment).
Run it with Docker goes from a clone to the first event. On SQLite the
image needs one volume and DATABASE_URL=file:/data/memento.db, and no postgres or redis
service (the SQLite guide); without Docker,
@jsmemento/server from npm runs the same server (Run it on a SQLite file).
One process or many
Section titled “One process or many”Without REDIS_URL one process stores events and streams them to its own clients from memory.
With Redis, run any number of processes against the same PostgreSQL and Redis: each publishes
what it stores, and a client connected to one sees events pushed to another
(Streaming). Each process applies pending migrations
when it starts, so roll out one process first. On SQLite there is always one server process,
with or without Redis.
PostgreSQL or SQLite
Section titled “PostgreSQL or SQLite”DATABASE_URL picks the database by its form, for the server, the CLI and connect() alike:
DATABASE_URL |
database |
|---|---|
postgresql://user:password@host:5432/db |
PostgreSQL, the default |
file:data/memento.db |
SQLite, relative to the working directory |
file:///var/lib/memento/memento.db |
SQLite, an absolute path |
:memory: |
SQLite in this process’s memory: tests only |
The API, the answers and the error codes are the same on both. What differs is what it needs and how far it goes:
| PostgreSQL (default) | SQLite (file:<path>) |
|
|---|---|---|
| what it needs | a PostgreSQL service (docker-compose.yaml: PostgreSQL 18) |
nothing: Node’s built-in node:sqlite (Node 24+), one file on a local disk |
| events (push, batch, query, Filter DSL, entity history, archive), templates and rendering, chats, seen / stars, tenants, API keys, lookups, the CLI | yes | yes |
UDC collections (events, cpu_load, activity, menu, the service site’s collections), filters, sorts, paging |
yes | yes, with the same answers |
the /ws stream |
yes. With Redis, across processes | yes, from the one process (the in-process bus) |
| daily quotas and rate limits | yes. Shared through Redis, or per process without it | yes, in the process: the quota from the usage table, rate limits in memory |
| self-service accounts and the service site | yes. The service site is a second container (service) |
accounts: yes. The service site: instead of the examples site, from the one process |
| retention | memento retention (cron, or the retention service) |
the same command, next to the running server |
Redis (REDIS_URL) |
optional. Needed for more than one process | optional and not needed. It does not allow a second server process |
| processes | any number of server processes | one server process; CLI commands may run next to it |
| hosts | any | one (the file and the server on the same machine) |
| backup | pg_dump |
VACUUM INTO, or a copy while stopped |
| scaling | more processes behind a proxy, with Redis | none: one process. Move to PostgreSQL when it is not enough |
| moving to the other database | no tool | no tool |
Choose SQLite for an installation that must not depend on a database service: memento on a customer’s own machine, an application that embeds memento and ships as one process, a demo, a development box. Choose PostgreSQL for more than one server process, the examples site and the service site side by side, or a database your operations already back up and monitor. The stage stack, the examples site and the service site run on PostgreSQL.
Pick the database when you install: there is no tool yet to move an installation from one to the other. Run it on a SQLite file is the shortest way to a server on one; the SQLite guide covers the image, embedding, accounts, retention, backups and the limits.
Hosted
Section titled “Hosted”The hosted service runs memento for anyone with a key: register,
verify the address, create a key on the Keys page, and push
to https://service.memento-service.org/memento. The account comes with its own tenant;
the key is held to a daily limit (100 000 events by default) and its usage is metered
(Tenants and API keys).
Nothing in a program changes between the three: the client programs read
MEMENTO_URL and MEMENTO_API_KEY, and point at the hosted service, a container or an embedded
server alike.
- Every variable of the server and the image: Environment.
- Running on one SQLite file: the SQLite guide.
- Reverse proxy, scaling, backups: docs/DEPLOYMENT.md.
v1.1.0released built 663143e