nestjs-boilerplate

Installation

NestJS Boilerplate supports TypeORM and Mongoose for working with databases. By default, TypeORM uses PostgreSQL as the main database, but you can use any relational database.

Switching between TypeORM and Mongoose is implemented based on the Hexagonal Architecture. This makes it easy to choose the right database for your application.


Table of Contents


Comfortable development (PostgreSQL + TypeORM)

  1. Clone repository

    git clone --depth 1 https://github.com/brocoders/nestjs-boilerplate.git my-app
    
  2. Go to folder, and copy env-example-relational as .env.

    cd my-app/
    cp env-example-relational .env
    
  3. Change DATABASE_HOST=postgres to DATABASE_HOST=localhost

    Change MAIL_HOST=maildev to MAIL_HOST=localhost

  4. Run additional container:

    docker compose up -d postgres adminer maildev
    
  5. Install dependency

    npm install
    
  6. Run app configuration

    You should run this command only the first time on initialization of your project, all next time skip it.

    If you want to contribute to the boilerplate, you should NOT run this command.

    npm run app:config
    
  7. Run migrations

    npm run migration:run
    
  8. Run seeds

    npm run seed:run:relational
    
  9. Run app in dev mode

    npm run start:dev
    
  10. Open http://localhost:3000

Video guideline (PostgreSQL + TypeORM)

https://github.com/user-attachments/assets/136a16aa-f94a-4b20-8eaf-6b4262964315


Comfortable development (MongoDB + Mongoose)

  1. Clone repository

    git clone --depth 1 https://github.com/brocoders/nestjs-boilerplate.git my-app
    
  2. Go to folder, and copy env-example-document as .env.

    cd my-app/
    cp env-example-document .env
    
  3. Change DATABASE_URL=mongodb://mongo:27017 to DATABASE_URL=mongodb://localhost:27017

  4. Run additional container:

    docker compose -f docker-compose.document.yaml up -d mongo mongo-express maildev
    
  5. Install dependency

    npm install
    
  6. Run app configuration

    You should run this command only the first time on initialization of your project, all next time skip it.

    If you want to contribute to the boilerplate, you should NOT run this command.

    npm run app:config
    
  7. Run seeds

    npm run seed:run:document
    
  8. Run app in dev mode

    npm run start:dev
    
  9. Open http://localhost:3000


Quick run (PostgreSQL + TypeORM)

If you want quick run your app, you can use following commands:

  1. Clone repository

    git clone --depth 1 https://github.com/brocoders/nestjs-boilerplate.git my-app
    
  2. Go to folder, and copy env-example-relational as .env.

    cd my-app/
    cp env-example-relational .env
    
  3. Run containers

    docker compose up -d
    
  4. For check status run

    docker compose logs
    
  5. Open http://localhost:3000


Quick run (MongoDB + Mongoose)

If you want quick run your app, you can use following commands:

  1. Clone repository

    git clone --depth 1 https://github.com/brocoders/nestjs-boilerplate.git my-app
    
  2. Go to folder, and copy env-example-document as .env.

    cd my-app/
    cp env-example-document .env
    
  3. Run containers

    docker compose -f docker-compose.document.yaml up -d
    
  4. For check status run

    docker compose -f docker-compose.document.yaml logs
    
  5. Open http://localhost:3000



Previous: Introduction

Next: Architecture