Skip to content

Latest commit

 

History

History
134 lines (90 loc) · 3.36 KB

File metadata and controls

134 lines (90 loc) · 3.36 KB

NestJS Starter-Kit [WIP]

Build Badge Tests Badge

This starter kit has the following outline:

  • Monolithic Project.
  • REST API

This is a Github Template Repository, so it can be easily used as a starter template for other repositories.

Sample implementations

To view sample implementations based on this starter-kit, please visit the nestjs-sample-solutions repository.

Starter-kit Features

Feature Info Progress
Authentication JWT Done
ORM Integration TypeORM Done
DB Migrations TypeORM Done
Logging nestjs-pino Done
Request Validation class-validator Done
Docker Ready Dockerfile Done
Continuous Code Quality SonarQube Done
Auto-generated OpenAPI - Done
Auto-generated ChangeLog - WIP

Installation

$ npm install

Create a .env file from the template .env.template.

Generate public and private key pair for jwt authentication:

$ ssh-keygen -t rsa -b 2048 -m PEM -f jwtRS256.key
# Don't add passphrase
$ openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

You may save these key files in ./local directory as it is ignored in git.

Encode keys to base64:

$ base64 -i local/jwtRS256.key

$ base64 -i local/jwtRS256.key.pub

Must enter the base64 of the key files in .env:

JWT_PUBLIC_KEY_BASE64=BASE64_OF_JWT_PUBLIC_KEY
JWT_PRIVATE_KEY_BASE64=BASE64_OF_JWT_PRIVATE_KEY

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Migrations

# generate migration (replace CreateUsers with name of the migration)
$ npm run migration:generate -- -n CreateUsers

# run migration
$ npm run migration:run

# revert migration
$ npm run migration:revert

SonarQube locally analyse

To locally analyse your code it is enough to run

# build image
$ docker-compose up

# run container from image
$ docker-compose exec sonarscanner sonar-scanner

The results can be viewed in local instance of sonarqube http://localhost:9000/sonarqube/dashboard?id=nest-typescript-starter.

Local instance of sonarqube uses sonar-scanner.properties file.

Docker

# build image
$ docker build -t my-app .

# run container from image
$ docker run -p 3000:3000 --volume `pwd`:/usr/src/app --env-file .env my-app

# run using docker compose
$ docker-compose up

Learn more about Docker conventions here. (WIP - Currently this is an internal org link.)