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',        // for profile files (still 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',
  },
})
💡All config values can also be set via environment variables: CONSENTI_DB_DRIVER, CONSENTI_DB_URI, CONSENTI_DB_DATABASE, etc. Code config takes precedence over env vars.

Frequently asked questions