This project aims to test RabbitMQ by consuming messages
The structure of this project consists of three parts.
- src folder: Source folder. This one contains the implementation of all features of the project as well as the
main.ts
that is the execution starting point. This folder must also include the unit tests. According to the best practices for NestJS, the unit tests will be added in the same folder that contains the module, service, and/or controller of a feature. The internal structure of the src folder is based on the structure of the NestJS modules. - test folder: This folder is meant to hold the e2e tests. The implementation of these tests must follow the principles of the NestJS testing definition.
- project configuration files (in ./): At the root of the project, some files were added to provide the configuration needed for some additional tools and services needed to get the microservices tested, built, and deployed.
The strategy to provide the configuration parameters of values to the application is based on the NestJS Configuration definition.
Environment variables may be added to the application by creating the .env
file at the root folder. This feature is meant to be used in the local environment of the developer. Since the environment variables are not the same for all environments, the .env
file was excluded from Git and needs to be created manually in the local environment.
This is an example of the .env
file
PORT=12345
DATABASE_USER=my-user
DATABASE_PASSWORD=my-user-password
For development, testing, and production environments the environment variables must be provided with their proper deployment scripts or procedures.
To avoid accessing the process.env
variable, NestJS provides the ConfigService. This service allows obtaining any configured variable by calling the get method and providing the variable name.
Example in main.ts:
const configService = app.get(ConfigService);
const port = configService.get('port');
The src/config folder is the folder where all code related to configuration must be added. Initially, this folder consists of three files:
- configuration.ts: this is for the configurations related to the application or main.ts
- cors.ts: this is for configurations related to CORS
- swagger.ts: this is for configurations related to Swagger
As with any NPM based project, it supports commands like install, start, and test. Additionally, the dockerize commands are also supported in this project due to the Dockerfile. These commands may be executed as follow:
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
docker build -t ${REPOSITORY_URL}/${IMAGE_NAME}:${IMAGE_VERSION} .
docker run --name=${APP_NAME} ${REPOSITORY_URL}/${IMAGE_NAME}:${IMAGE_VERSION}
The implementation of Swagger (OpenAPI) is based on the OpenAPI module of NestJS. The official documentation may be accessed for further questions.
The Swagger documentation of this project is available on ${HOSTNAME}:${PORT}/api
.