- Summary
- System Design
- Swagger UI APIs
- Local Development
- Docker Usage
- End to end integration tests
- Script
- Database Management
To run locally, ensure that Node.js and npm are installed on your machine. If not installed, follow the official installation guide for Node.js to get started.
From the project's root directory, navigate to the app/
folder and install the required dependencies using:
$ cd app
$ npm install
$ npm run build
Make sure you have a database ready to serve before starting the server. To start the server locally, use:
$ npm run start
Run ESLint to lint your TypeScript code:
$ npm run format
$ npm run lint
To successfully create a connection to the PostgreSQL you need to create a .env file with a ${DATABASE_URL}
inside the app/prisma/
folder. The format of the url string is:
postgres://[username]:[password]@[host]:[port]/[database_name]
Docker is utilized for containerized deployment, making it easy to manage dependencies and ensure consistent environments.
For Docker-based deployment, make sure Docker and Docker Compose are installed on your machine. If not installed, follow the official installation guides for Docker and Docker Compose.
Use the following command to build the project:
$ docker-compose build
$ docker-compose up --detach db
The database will be listening for at port 5432
within the container network. For outside connections, it will listen at port 2345
, you must refer to it as localhost:2345
, example:
NAME | IMAGE | COMMAND | SERVICE | CREATED | STATUS | PORTS |
---|---|---|---|---|---|---|
nodenestjs-db-1 | postgres | docker-entrypoint.s… | db | 4 days ago | Up 4 minutes | 0.0.0.0:2345->5432/tcp |
To start the servers and the load balancer
$ docker-compose up --detach server_0 server_1 server_2
$ docker-compose up --detach nginx
Each server will be listening for at the port ${SERVER_*_PORT}
within the container network.
You don't access the server directly, but through nginx, with a self signed certificate. For outside connections, you must refer to it as https://localhost:${NGINX_EXPOSED_PORT}
, example:
NAME | IMAGE | COMMAND | SERVICE | CREATED | STATUS | PORTS |
---|---|---|---|---|---|---|
nodenestjs-server_0-1 | nodenestjs-server_0 | docker-entrypoint.s… | server_0 | 40 minutes ago | Up 40 minutes | |
nodenestjs-server_1-1 | nodenestjs-server_1 | docker-entrypoint.s… | server_1 | 40 minutes ago | Up 40 minutes | |
nodenestjs-server_2-1 | nodenestjs-server_2 | docker-entrypoint.s… | server_2 | 40 minutes ago | Up 40 minutes | |
nodenestjs-nginx-1 | nodenestjs-nginx | /docker-entrypoint.… | nginx | 40 minutes ago | Up 40 minutes | 80/tcp, 0.0.0.0:3000->443/tcp |
Once the server is running, you can access the Swagger documentation by navigating to https://localhost:3000/docs
in your web browser.
For logs output, you can use this command:
$ docker-compose logs -f server_0
$ docker-compose logs -f server_1
$ docker-compose logs -f server_2
To stop the running services and release resources, use the following command:
$ docker-compose down
The main goal of this test suite is to setup all containers and make sure things are working fine at a close to production environment.
Use the following command to run end to end integration tests:
$ docker-compose run e2e
From the project's root directory, navigate to the app
folder and run tests using:
$ cd app
$ npm run test
$ ./script/lint.sh
$ ./script/start.sh
$ ./script/test.sh
In order to replicate the pipeline, you can run these commands:
$ ./script/pipeline/run.sh lint
$ ./script/pipeline/run.sh test
Server relies on a database to store application data. To manage the database schema and data, we use Prisma Migrate for database migrations and Prisma Client for database interactions.
Database migrations are essential for managing changes to the database schema over time. Whenever there are changes to the schema, such as adding new tables or modifying existing ones, it's crucial to create and apply migrations to keep the database schema in sync with the application's requirements.
To run database migrations, use the following command:
$ cd app
$ npm run prisma:migrate
This command applies any pending migrations to the database. It's recommended to run migrations whenever there are changes to the database schema.