Check the contributing manual
The best nestjs boilerplate using Anti-corruption Layer pattern, secrets, error handler, logger, Mysql, Docker and unit tests.
nest framework documentaion.
conventionalcommits framework documentaion.
commitizen framework documentaion.
- [docker]
- [docker-compose]
- [yarn]
- [NVM]
- Node >=14 <=15
/jest/init.ts
: Test startup settings like envs and mocks.src/main.ts
: Application entry point.src/modules/
: Application modules, may contain; services, controller, repositories and etc.src/modules/common/
: Common modules that used for two or many modules.src/modules/common/**/adpater.ts
: Used to communicated with controller and others modules. Controllers and Modules must communicated with abstraction, not implementation.src/modules/global/
: Globals modules that is visibles for all modules.src/utils/
: Utilities for the application that will not necessarily only be used within modules.src/static/
: Application static files like JSON, CSV etc.
- create file
$ touch .env
- add on file
ENV=dev
PORT=3000
TZ='America/Sao_Paulo'
# url
HELLO_WORD_SERVICE='https://sandbox.api.service.nhs.uk/hello-world/hello/world'
# database
DB_HOST='db'
DB_USERNAME='root'
DB_PASSWORD='admin'
DB_DATABASE='customer'
--
$ yarn
--
# development
$ yarn start:dev
# dev/hml/prd environment
$ docker-compose up --build
--
# unit tests
$ yarn test
# e2e tests
$ yarn test:e2e
# test coverage
$ yarn test:coverage
--
# swagger documentation
http://localhost:3000/api/#/
--
# create migration
$ yarn migration:create --name=<migrationname>
--
$ yarn tag:production
--
- throw error
import { AppException } from 'utils/error';
throw new AppException({
error: 'Error message',
status: HttpStatus.INTERNAL_SERVER_ERROR, //optional
});
- logs
import { ILoggerService } from '../global/logger/adapter';
export class Example {
constructor(
private readonly loggerService: ILoggerService,
) {}
async example(): void {
this.loggerService.log(
data.message,
`${Example.name}/${this.example.name}`,// log context
);
this.loggerService.error(new ErrorRest({
error: 'Error message',
status: HttpStatus.INTERNAL_SERVER_ERROR, //optional
}));
}
}
- envs
import { ISecretsService } from '../global/secrets/adapter';
@Injectable()
export class Example {
constructor(
private readonly secretService: ISecretsService,
) {}
async example(): void {
this.secretService.url.HELLO_WORD;
}
}
The following is a list of all the people that have contributed to nest-boilerplate. Thanks for your contributions!
It is available under the MIT license. License