- Azversan NestJS Module Boilerplate
A production-ready boilerplate for building scalable and reusable NestJS modules with TypeScript.
Designed for creating publishable NestJS packages with:
- Dynamic module support
- Sync & async configuration
- Custom exception factory pattern
- Typed interfaces
- Jest testing
- ESLint + Prettier
- ✅️ NestJS Dynamic Module pattern
- ✅️
register()andregisterAsync()support - ✅️ Fully typed configuration interfaces
- ✅️ Custom exception factory support
- ✅️ Unit testing with Jest
- ✅️ ESLint v9 flat config
- ✅️ Prettier formatting
- ✅️ Ready for open-source package distribution
npm install @azversan/dummyRequired peer dependencies:
npm install @nestjs/common @nestjs/core reflect-metadata rxjsimport { Module } from '@nestjs/common';
import { DummyModule } from '@azversan/dummy';
@Module({
imports: [
DummyModule.register({
exceptionFactory: (err) => new Error(`[${err.code}] ${err.message}`),
}),
],
})
export class AppModule {}import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { DummyModule } from '@azversan/dummy';
@Module({
imports: [
ConfigModule.forRoot(),
DummyModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
exceptionFactory: (err) => new Error(err.message),
}),
}),
],
})
export class AppModule {}import { Injectable } from '@nestjs/common';
import { DummyService } from '@azversan/dummy';
@Injectable()
export class AppService {
constructor(private readonly dummyService: DummyService) {}
hello(): string {
return this.dummyService.greet('World');
}
}The module supports a customizable exception factory.
If no factory is provided, the module throws:
HttpException(message, 500);DummyModule.register({
exceptionFactory: (error) => {
return new Error(`[${error.code}] ${error.message}`);
},
});Register the module synchronously.
| Property | Type | Description |
|---|---|---|
exceptionFactory |
(error) => Error |
Custom exception creator |
Register the module asynchronously.
| Property | Description |
|---|---|
imports |
Imported modules |
inject |
Providers to inject |
useFactory |
Factory function |
useClass |
Class-based factory |
useExisting |
Existing provider |
# Build package
npm run build
# Run tests
npm run test
# Run tests with coverage
npm run test:cov
# Run ESLint
npm run lint
# Format code
npm run formatsrc/
├── dummy/
│ ├── interfaces/
│ ├── __tests__/
│ ├── dummy.constants.ts
│ ├── dummy.module.ts
│ └── dummy.service.ts
└── index.ts
This project uses:
- Jest
- ts-jest
- @nestjs/testing
Run all tests:
npm run testRun coverage:
npm run test:cov