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
| Driver | Node req. | Extra install | Best for |
|---|---|---|---|
| json | ≥ 20 | None | Development, small/personal sites |
| node:sqlite | ≥ 22.5 | None (built-in) | Single-server production, low/medium traffic |
| node-sqlite3-wasm | ≥ 20 | npm install node-sqlite3-wasm | Node 20/21, no C++ toolchain |
| better-sqlite3 | ≥ 20 | npm install better-sqlite3 | Highest-performance SQLite, needs C++ toolchain |
| postgresql | ≥ 20 | npm install pg | Multi-server production, high traffic, existing PG infra |
| mysql | ≥ 20 | npm install mysql2 | Multi-server production, existing MySQL infra |
| mongodb | ≥ 20 | npm install mongodb | Document-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.
createConsenti({
storage: { driver: 'json', path: './consenti-data' },
// ...
})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.
// 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
// 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
// npm install mongodb
createConsenti({
storage: {
driver: 'mongodb',
uri: process.env.MONGODB_URI, // e.g. mongodb://localhost:27017/consenti
database: 'consenti',
path: './consenti-data',
},
})CONSENTI_DB_DRIVER, CONSENTI_DB_URI, CONSENTI_DB_DATABASE, etc. Code config takes precedence over env vars.