NestJS
One import auto-instruments your entire NestJS app. Every HTTP request, exception, and database query appears in Fanar automatically — no decorators, no boilerplate.
Installation
npm install @fanar-app/fanar FanarModule.forRoot()
Register the module in your root AppModule. This installs a global interceptor that captures every request.
import { FanarModule } from '@fanar-app/fanar/nestjs'
@Module({
imports: [
FanarModule.forRoot({ enabled: true }),
],
})
export class AppModule {} | Option | Default | Description |
|---|---|---|
| enabled | true | Set to false to disable without removing the import |
| host | localhost | Fanar desktop app hostname |
| port | 23517 | Fanar desktop app port |
FanarModule.forRootAsync()
Use when options come from a config service or environment variables.
import { FanarModule } from '@fanar-app/fanar/nestjs'
import { ConfigService } from '@nestjs/config'
@Module({
imports: [
FanarModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
enabled: config.get('NODE_ENV') === 'development',
port: config.get('FANAR_PORT'),
}),
}),
],
})
export class AppModule {} @Fanar() decorator
Wrap any service method to automatically send its arguments, return value, and execution time.
import { Fanar } from '@fanar-app/fanar/nestjs'
@Injectable()
export class UserService {
@Fanar()
async findById(id: string): Promise<User> {
return this.repo.findOne(id)
}
} Works with sync methods, async methods, and async generators. Exceptions are re-thrown after being sent.
TypeORM integration
Pass FanarTypeOrmLogger as the TypeORM logger to capture all queries.
import { FanarTypeOrmLogger } from '@fanar-app/fanar/nestjs'
TypeOrmModule.forRoot({
type: 'postgres',
// ...
logger: new FanarTypeOrmLogger(),
}) Prisma integration
Wrap your PrismaClient instance with withFanar(). Requires Prisma's query event logging to be enabled.
import { withFanar } from '@fanar-app/fanar/nestjs'
import { PrismaClient } from '@prisma/client'
const prisma = withFanar(
new PrismaClient({
log: [{ emit: 'event', level: 'query' }],
})
) FanarInterceptor
If you prefer not to use FanarModule, you can apply the interceptor manually to specific controllers or routes.
import { FanarInterceptor } from '@fanar-app/fanar/nestjs'
@UseInterceptors(FanarInterceptor)
@Controller('users')
export class UsersController {} What gets captured automatically
- Every HTTP request — method, path, status code, duration, query count
- Uncaught exceptions — with stack trace
- TypeORM queries — SQL, bound values (via
FanarTypeOrmLogger) - Prisma queries — SQL, bound values (via
withFanar())