Consenti
Tutorial — Frontend + Backend — Step 1 of 9

Install Backend

Add @consenti/api to your Node.js server.

bash
npm install @consenti/api

Zero runtime dependencies — only Node.js built-ins. createConsenti() returns a router, a handler, and adapters for every major framework — pick the one that matches your stack.

Express

app.ts
ts
import express from 'express'
import { createConsenti } from '@consenti/api'

const app = express()
const consenti = createConsenti({
  storage: { driver: 'json', path: './consenti-data' },
  auth: { mode: 'local', adminEmail: '[email protected]', adminPassword: process.env.CONSENTI_ADMIN_PASSWORD! },
  dashboard: true,
})
app.use(consenti.router)
app.listen(3000)

Standalone — no existing server

server.ts
ts
import { createConsenti } from '@consenti/api'
import http from 'node:http'

const consenti = createConsenti({
  storage: { driver: 'json', path: './consenti-data' },
  auth: {
    mode: 'local',
    adminEmail: '[email protected]',
    adminPassword: process.env.CONSENTI_ADMIN_PASSWORD!,
  },
  dashboard: true,
})

http.createServer(consenti.handler).listen(3001)
// Admin dashboard → http://localhost:3001/consenti/
// REST API        → http://localhost:3001/consenti/api/v1/

Fastify

app.ts
ts
import Fastify from 'fastify'
import { createConsenti } from '@consenti/api'

const fastify = Fastify()
const consenti = createConsenti({
  storage: { driver: 'json', path: './consenti-data' },
  auth: { mode: 'local', adminEmail: '[email protected]', adminPassword: process.env.CONSENTI_ADMIN_PASSWORD! },
  dashboard: true,
})

await fastify.register(consenti.fastifyHandler)
await fastify.listen({ port: 3000 })

Next.js App Router

app/consenti/[...path]/route.ts
ts
import { createConsenti } from '@consenti/api'
import type { NextRequest } from 'next/server'

let consenti: Awaited<ReturnType<typeof createConsenti>>

async function getConsenti() {
  if (!consenti) {
    consenti = createConsenti({
      storage: { driver: 'node:sqlite', path: './consenti-data' },
      auth: {
        mode: 'local',
        adminEmail: process.env.CONSENTI_ADMIN_EMAIL!,
        adminPassword: process.env.CONSENTI_ADMIN_PASSWORD!,
      },
    })
  }
  return consenti
}

async function consentiHandler(req: NextRequest) {
  const c = await getConsenti()
  return c.handleRequest(req)
}

export { consentiHandler as GET, consentiHandler as POST, consentiHandler as PUT, consentiHandler as DELETE, consentiHandler as PATCH }

Hono / Cloudflare Workers / Deno / Bun (edge runtimes)

consenti.honoApp is a WinterCG-compatible { fetch } handler — works with Hono directly, or anywhere that accepts a standard fetch handler.

Hono
ts
import { Hono } from 'hono'
import { createConsenti } from '@consenti/api'

const consenti = createConsenti({ /* ... */ })

const app = new Hono()
app.all('/consenti/*', (c) => consenti.honoApp.fetch(c.req.raw))
💡consenti.handler is a standard http.IncomingMessage → http.ServerResponse handler — any Node.js HTTP framework not listed above can still wrap it directly. Full reference on the Backend Installation and API Methods pages.