Boilerplate for a TCP Microservice in NestJS with TypeORM and tests
.env
file to indicate required environment variablesCustomResponse
interface includes the namespace
nowcross-env
to set the NODE_ENV
for cross OS supportutils
to simply custom-response
CustomResponse
interface is a generic nowWARNING = 'warning'
config.service
will use now process.cwd()
istead of a relative pathconfig.service
will return the values from .env
files or from process.env
database.module
will receive each entity inside the entities
instead of 'dist/**/*.entity{.ts,.js}'
For a better understanding, check out this article.
install the desired database, this example is made with MariaDB link to a youtube tutorial
install Pachet Sender (like Postman for TCP) download link
download the code and run npm i
Now is time to write your configuration for this project. Create two files: .env.development and .env.test.
! Both will be ignored with .gitignore
! In production instead of these two, create a new file on your server named .env.production
This is an example for .env.development ! Replace with your config
DB_SERVER_PORT=3306
DB_SERVER_HOST=localhost
DB_SERVER_USERNAME=root
DB_SERVER_PASSWORD=root
DATABASE=users
ERROR_CODE_NAMESPACE=users-microservice
:8875
{
"status":ResponseStatus
"data":any -> '' when no data is found
"error":CustomError
}
ResponseStatus - "success" or "fail"
CustomError - consist of 3 parts: an error code, a message and a namespace. Codes are universal, but messages can vary. Here is the error JSON payload:
{
"code":number,
"msg":string || string[]
"namespace":string
}
1000 UNKNOWN
1001 DATABASE_ERROR
1100 BAD_PARAMETERS