Consenti

Choosing a Storage Driver

Consenti ships a zero-config JSON file storage driver that works out of the box. When you outgrow it, you can swap to SQLite, PostgreSQL, MySQL, or MongoDB with a single config change. This guide explains the trade-offs and gives you a config snippet for each.

Decision guide

DriverNode req.Extra installBest for
json≥ 20NoneDevelopment, small/personal sites
node:sqlite≥ 22.5None (built-in)Single-server production, low/medium traffic
node-sqlite3-wasm≥ 20npm install node-sqlite3-wasmNode 20/21, no C++ toolchain
better-sqlite3≥ 20npm install better-sqlite3Highest-performance SQLite, needs C++ toolchain
postgresql≥ 20npm install pgMulti-server production, high traffic, existing PG infra
mysql≥ 20npm install mysql2Multi-server production, existing MySQL infra
mongodb≥ 20npm install mongodbDocument-oriented workloads, existing Mongo infra

JSON (default)

No installation, no setup. Consenti writes a consenti-data.json file to the configured storage.path. Suitable for development and deployments with very low write volume.

typescript
createConsenti({
  storage: { driver: 'json', path: './consenti-data' },
  // ...
})
⚠️JSON storage reads and writes the entire file on every operation. It is not suitable for concurrent access or high write volume. Migrate to SQLite or a database before going to production.

SQLite

SQLite runs in-process — no separate database server, no connection string. It handles hundreds of writes per second and is a great production choice for single-server deployments.

// No extra install — uses Node's built-in SQLite
createConsenti({
  storage: { driver: 'node:sqlite', path: './consenti-data' },
})

PostgreSQL

Use PostgreSQL when you need multi-server deployments, an existing PG infrastructure, or higher write throughput than SQLite can provide. Consenti uses pg (the pg package) as the driver.

typescript
// npm install pg
createConsenti({
  storage: {
    driver: 'postgresql',
    uri: process.env.DATABASE_URL,  // e.g. postgresql://user:pass@host:5432/consenti
    database: 'consenti',           // optional if included in uri
    path: './consenti-data',        // required — profile files are always written locally
  },
})

MySQL

typescript
// npm install mysql2
createConsenti({
  storage: {
    driver: 'mysql',
    uri: process.env.DATABASE_URL,  // e.g. mysql://user:pass@host:3306/consenti
    database: 'consenti',
    path: './consenti-data',
  },
})

MongoDB

typescript
// npm install mongodb
createConsenti({
  storage: {
    driver: 'mongodb',
    uri: process.env.MONGODB_URI,   // e.g. mongodb://localhost:27017/consenti
    database: 'consenti',
    path: './consenti-data',
  },
})
⚠️storage.path is required with every database driver. The database stores consent records, users and templates; profiles are stored as files under storage.path/profiles/. Keep that directory on persistent storage, shared between instances if you run more than one.
ℹ️With these three drivers every table (collection) is named consenti_* (consenti_users, consenti_profiles, …), so Consenti can't clash with another app's tables. Upgrading an existing PostgreSQL / MySQL / MongoDB install from before 0.6.0 needs a one-off rename. On shared hosting with a restricted database user, see what it needs — the connection pool defaults to 5 (storage.poolMax) for exactly that case.

Environment variables

All config values can also be set via environment variables. Code config takes precedence over env vars. CONSENTI_DB_PATH is always needed.

.env — PostgreSQL
bash
CONSENTI_DB_DRIVER=postgresql
CONSENTI_DB_PATH=./consenti-data
CONSENTI_DB_URI=postgresql://consenti:your-password@localhost:5432/consenti
.env — MySQL / MariaDB
bash
CONSENTI_DB_DRIVER=mysql
CONSENTI_DB_PATH=./consenti-data
CONSENTI_DB_HOST=localhost
CONSENTI_DB_PORT=3306
CONSENTI_DB_USER=consenti
CONSENTI_DB_PASSWORD=your-password
CONSENTI_DB_DATABASE=consenti
# or: CONSENTI_DB_URI=mysql://consenti:your-password@localhost:3306/consenti
.env — MongoDB
bash
CONSENTI_DB_DRIVER=mongodb
CONSENTI_DB_PATH=./consenti-data
CONSENTI_DB_URI=mongodb://consenti:your-password@localhost:27017/?authSource=admin
CONSENTI_DB_DATABASE=consenti

Frequently asked questions