Skip to content

SaidMg10/cars-nestjs

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

Personal Template for Building Projects with My Team, Based on NestJS Best Practices

Project Overview

This template was created to streamline the development of projects with my team, making it easier and more comfortable to kick-start new services. It is based on a NestJS template and modified to fit our specific needs. It includes essential tools like Docker, ESLint, Husky for linting, and a flexible directory structure for rapid development.

This template was inspired by the work of Albert Hernandez, whose video and repository helped guide the creation of this project. Modifications include using Express, adding Yarn as a package manager, and making adjustments to the database configuration for personal convenience and flexibility.

Credits

This project is based on the work of Albert Hernandez. The original template was modified to use Express, added Yarn as a package manager, and adjusted configurations for the database. All credit goes to the original creator.

Prerequisites

Before starting, make sure you have the following installed:

Project setup

$ yarn install

Env Configuration

  1. Clone the .env.template file and rename it according to the environment:
  • For development: .env.development
  • For production: .env.production
  • For testing: .env.testing
  • Or use a general: .env
  1. Fill in the file with the corresponding values for each environment

  2. Make sure not to commit .env files to the repository (they should be included in .gitignore)

Compile and run the project

# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod

Compile and Run the Project with Docker

  • For the initial creation, we will always use the --build command, for example: docker-compose up --build or docker-compose build.
  • For detached mode, we will add the -d flag at the end of the command, for example: docker-compose up --build -d.
  • If the --build has already been done, to start the project, we only need to use docker-compose up.
  • If we want to remove everything, we will use docker-compose down.

Running the Backend and Database

You can run the project with or without the database depending on your needs:

  • To run only the backend (without the database):

    docker-compose up backend-dev
  • To run the database (without the backend):

    docker compose --env-file 'your .env path' up template_db
  • To run everything together (both backend and database):

    docker compose --env-file 'your .env path' up backend-dev template_db
  • To run everything (without profiles)

    docker-compose up

Select the Development Environment

To choose the environment in which the application will run, use the following commands:

# Development Mode
$ docker-compose --env-file .env.development up

# Production Mode
$ docker-compose --env-file .env.production up

# Test Mode
$ docker-compose --env-file .env.testing up

Run tests

# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov

This development mode will work with hot-reload and expose a debug port, port 9229, so later we can connect to it from our editor.

Now, you should be able to start debugging configuring using your IDE. For example, if you are using vscode, you can create a .vscode/launch.json file with the following configuration:

{
  "version": "0.1.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach to docker",
      "restart": true,
      "port": 9229,
      "remoteRoot": "/app"
    }
  ]
}

About

Es un proyecto o aplicación desarrollada utilizando el framework NestJS, que está diseñado para construir aplicaciones del lado del servidor (backend) eficientes, escalables y mantenibles.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors