Coder Social home page Coder Social logo

nodenestjs's Introduction

Introduction

Node.js project designed for building scalable and modular server-side applications using NestJS.

  1. Local Development
  2. Docker usage
  3. End to end integration tests
  4. Script
  5. Database Management

Local Development

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.

Installation

From the project's root directory, navigate to the app/ folder and install the required dependencies using:

$ cd app
$ npm install

Build

Use the following command to build the project:

$ npm run build

Start Server Locally

Make sure you have a database ready to serve before starting the server. To start the server locally, use:

$ npm run start

Lint

Run ESLint to lint your TypeScript code:

$ npm run lint

Format

Format your code:

$ npm run format

Database Connection

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 Usage

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.

Build

Use the following command to build the project:

$ docker-compose build

Start Database locally

$ 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

Start Server Locally

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

Stopping Services

To stop the running services and release resources, use the following command:

$ docker-compose down

End to end integration tests

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.

Run

Use the following command to run end to end integration tests:

$ docker-compose run e2e

Development

From the project's root directory, navigate to the app folder and run tests using:

$ cd app
$ npm run test

Script

Cleanup

$ ./script/cleanup.sh

Lint

$ ./script/lint.sh

Start

$ ./script/start.sh

Test

$ ./script/test.sh

Pipeline

In order to replicate the pipeline, you can run these commands:

Lint

$ ./script/pipeline/run.sh lint

Test

$ ./script/pipeline/run.sh test

Database Management

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

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.

Running Migrations

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.

nodenestjs's People

Contributors

dependabot[bot] avatar gardusig avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.