Skip to content

Run it on a SQLite file

memento runs on PostgreSQL or on a single SQLite file. On SQLite the server needs Node 24 and a local disk, nothing else: no Docker, no database service, no Redis. The driver is Node’s built-in node:sqlite, and the memento command line opens the same file directly.

  1. Make a directory and install the server and the command line (Node 24 or newer, curl and jq):

    Terminal window
    mkdir my-memento && cd my-memento
    npm install @jsmemento/server @jsmemento/cli
  2. Point memento at a database file. A relative file: path is relative to the working directory; file:///var/lib/memento/memento.db is an absolute one. Leave REDIS_URL unset:

    Terminal window
    export DATABASE_URL=file:data/memento.db # the database, one file; no REDIS_URL
    export PORT=9300 # the default is 8000
  3. Create the database. The server would also migrate at start; memento migrate creates the file and its directory now:

    Terminal window
    npx memento migrate
    ls data
    What it printed
    migrations applied
    memento.db
  4. Make a tenant and an API key of it. No server has to be running, because each command opens the file. The mk_… secret is printed once; only a hash of it is stored:

    Terminal window
    npx memento create-tenant acme --name "Acme Inc"
    npx memento create-key --tenant acme --scopes read,write --name backend
    What it printed
    created tenant acme (Acme Inc) id=01a1e1f1-7334-7cae-962d-0771cf7ccc9a
    created key "backend" for acme [read,write]
    prefix: azvue4n7
    key: mk_azvue4n7_…
    Store it now: it cannot be shown again.
  5. Start the server. Its log is JSON on stdout, with no Redis line and no PostgreSQL line. The warnings about lookups.yaml and menu.yaml are expected for an npm install: both files are optional, the image bundles them, and events still render from the templates in the package.

    Terminal window
    node node_modules/@jsmemento/server/dist/server.js
    What it printed
    {"level":30,…,"database":"SQLite …/my-memento/data/memento.db","msg":"database migrated and open"}
    {"level":30,…,"path":"…/my-memento/node_modules/lookups.yaml","sections":[],"strict":false,"msg":"lookups loaded"}
    {"level":40,…,"msg":"…/my-memento/node_modules/lookups.yaml not found: lookups disabled"}
    {"level":40,…,"msg":"…/my-memento/node_modules/menu.yaml not found: no menu UDC collection"}
    {"level":30,…,"msg":"Server listening at http://127.0.0.1:9300"}
  6. In a second terminal, in the same directory, push the first event and read the history of user/42 back, rendered in Serbian:

    Terminal window
    export KEY=mk_… # what create-key printed
    curl -s localhost:9300/memento/api/health; echo
    curl -s -X POST localhost:9300/memento/events -H "Authorization: Bearer $KEY" \
    -H 'content-type: application/json' \
    -d '{"event_type":"USER_LOGIN","instance_type":"user","instance_id":42,"actor_id":"igor"}' \
    | jq '.data | {event_type, instance_type, instance_id, rendered}'
    curl -s "localhost:9300/memento/entities/user/42/events?locale=sr" -H "Authorization: Bearer $KEY" \
    | jq -c '[.data[] | {event_type, actor_id, rendered}]'
    ls data
    What it printed
    {"ok":true,"data":{"status":"ok"}}
    {
    "event_type": "USER_LOGIN",
    "instance_type": "user",
    "instance_id": "42",
    "rendered": "User igor logged in."
    }
    [{"event_type":"USER_LOGIN","actor_id":"igor","rendered":"Korisnik igor se prijavio."}]
    memento.db
    memento.db-shm
    memento.db-wal

    memento.db-wal and memento.db-shm are part of the database while the server has it open. Stop the server with Ctrl-C: it closes the file cleanly, and only memento.db remains.

Events, the Filter DSL, entity history, templates, chats, tenants and keys, the UDC collections and the /ws stream answer the same as on PostgreSQL. What changes is how far it scales:

  • One server process on the file, on one host. Your own application counts as that process when it embeds the plugin. memento CLI commands next to it are fine. For more than one server, use PostgreSQL.
  • No Redis needed. The process streams what it stores to its own /ws clients, and keeps the rate limits and quota counts itself. REDIS_URL is accepted, but it does not allow a second server process.
  • The examples site or the service site, one per process, not both side by side.
  • The file on a local disk. Never on NFS or SMB, and never opened from two hosts.

Deployment modes has the features by database, and the SQLite guide has the rest: the image and Compose on one file, accounts and the service site, retention from cron, backups with VACUUM INTO, restores, upgrades and what not to do with the file.

  • Push from your own code: the client programs work against this server with MEMENTO_URL=http://localhost:9300/memento.
  • Every route, with its answers and error codes: HTTP API.
  • Every variable the server reads, DATABASE_URL first: Environment variables.

v1.1.0released built 663143e