@nestarc/feature-flag
DB-backed feature flags for NestJS + Prisma + PostgreSQL -- tenant-aware overrides, percentage rollouts, and zero external dependencies.
Features
- Database-backed -- flags stored in PostgreSQL via Prisma, no external service required
- Tenant / user / environment overrides -- granular control per tenant, user, or deployment environment
- Percentage rollouts -- deterministic hashing (murmurhash3) for consistent per-user bucketing
- Guard decorator --
@FeatureFlag()automatically gates routes and controllers - Bypass decorator --
@BypassFeatureFlag()exempts health checks and public endpoints - Programmatic evaluation --
isEnabled(),evaluateAll(), andfindByKey()for service-layer logic - Detailed evaluation --
evaluateBoolean()returns source, reason, fallback, targeting, bucket, and timing metadata - Type-safe registries --
defineFlags(), generated clients/decorators, defaults, and lifecycle status helpers - Pluggable cache --
CacheAdapterinterface with built-inMemoryCacheAdapter(default) andRedisCacheAdapterv0.2.0 - Redis Pub/Sub -- cross-instance cache invalidation for horizontal scaling v0.2.0
- Admin REST API -- opt-in
FeatureFlagAdminModulewith mandatory guard injection v0.2.0 - Repository pattern --
FeatureFlagRepositoryinterface for custom persistence backends v0.2.0 - Tenant context provider -- automatic
@nestarc/tenancyintegration viaTenantContextProviderv0.2.0 - Event system -- optional integration with
@nestjs/event-emitterfor audit and observability - Testing utilities -- drop-in
TestFeatureFlagModulefor unit and integration tests
Installation
bash
npm install @nestarc/feature-flagPeer dependencies
bash
npm install @nestjs/common @nestjs/core @prisma/client @prisma/adapter-pg pg class-transformer class-validator rxjs reflect-metadata
npm install --save-dev prismaVersion 0.5 requires Prisma 7 and Node.js ^20.19.0, ^22.12.0, or >=24.0.0. See Installation for the generated-client setup. No database migration is required when upgrading from 0.4.
Optional
bash
# Required only if you enable emitEvents
npm install @nestjs/event-emitter
# Required only if you use RedisCacheAdapter
npm install ioredis