Skip to content
/ nestjs-starter Public template

Nest framework starter repository. Using Typeorm, Docker, Swagger, Class-Validation and includes already code for testing with fixtures, authentication and permission based authorization.

Notifications You must be signed in to change notification settings

MSWagner/nestjs-starter

Repository files navigation

Testing

Nest Logo

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

NPM Version Package License NPM Downloads Travis Linux Coverage Discord Backers on Open Collective Sponsors on Open Collective

Description

Nest framework TypeScript starter repository.

Start

Replace the string 'project-name' in all files of the project with your own project name. (For example with the search/replace function from visual studio code)

Files to edit:

  • docker-compose.yml
  • docker-compose.dev.yml
  • docker-compose.test.yml
  • docker-compose.prod.yml
  • prod.env
  • dev.env
  • test.env
  • test.docker.env

Important to avoid docker container naming conflicts!

Create or edit your local .env file

Set up the environment variable COMPOSE_FILE to avoid the 'Found orphan containers' warning:

MacOS:

COMPOSE_FILE=docker-compose.prod.yml:docker-compose.dev.yml:docker-compose.test.yml

Windows:

COMPOSE_FILE=docker-compose.prod.yml;docker-compose.dev.yml;docker-compose.test.yml

Installation

$ yarn
$ yarn build

Development

Starting the dev enviornment (Docker Container)

# create docker network for database connection
$ docker network create project-name-network-dev

# start the app and database in docker containers
$ docker-compose -f 'docker-compose.dev.yml' up

# start first migration to create the db tables
$ yarn db:migrate:dev

Testing Local (without app docker container)

# start test database in docker container
$ docker-compose -f 'docker-compose.test.yml' up

# start first migration to create the db tables
$ yarn db:migrate:test

# unit tests
$ yarn test

# watch mode
$ yarn test:watch

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov

Testing in Docker Container

# start docker containers (app, dev + test)
$ yarn docker:up:hidden

# start first migration to create the db tables
$ yarn docker:db:migrate

# execute tests in the docker container
$ yarn docker:test

Deployment

First Start

  • To create a docker image + container with the app & database.
# create network to connect the app with the db
$ docker network create project-name-network

# set the env variables for the docker compose file (I used github secrets in the github actions pipeline)
# build the docker image, create & run the app/db container in detached mode (background) 
$ docker-compose -f 'docker-compose.prod.yml' up -d

# init tables with migration
$ docker-compose exec app yarn db:migrate:prod

Docker App Update

  • To update the docker image and start the new docker container
$ docker build -t project-name .
$ docker-compose up -d

Docker Migration

  • To run new migrations
# start migrations
$ docker-compose exec app yarn db:migrate:prod

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

About

Nest framework starter repository. Using Typeorm, Docker, Swagger, Class-Validation and includes already code for testing with fixtures, authentication and permission based authorization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages