0.1.5 • Published 3 years ago

nestjs-starter v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Description

This project for beginners made of Nest combined with some powerful libraries such as: Fastify, Sequelize, JWT... written in Typescript and uses PostgreSQL as the database.

Introduction

This source code to help you get started with Nestjs.

Installation

Source code works on Node version 14.17.1 and Yarn version 1.22.10. If you don't have it, install it first. The setup and startup steps I describe in the Installation section.

1. Open Git bash.
2. git clone https://github.com/pktai/nestjs-starter.git.
3. cd nestjs-starter.
4. yarn. // install library.
5. setup .env file. Please open the file `env.example` and set the environment variables properly.

Below are the variables in env.

NODE_ENV=development

DB_DIALECT=postgres
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=language
DB_HOST=127.0.0.1
DB_PORT=5432

SECRET_TOKEN=jsonwebtoken
EXPIRESIN_ACCESS_TOKEN=5m
EXPIRESIN_REFRESH_TOKEN=15m

RATE_LIMIT_TIME_WINDOW=30000
RATE_LIMIT_MAX=100
DEFAULT_LIMIT_PAGE=10

SERVICE_PORT=3001
SERVICE_NAME='0.0.0.0'
MONGO_DB=mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false

Running the app

# development
$ yarn start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Test

Before running the test command. you need to run command yarn db:migrate to init data

# unit tests
$ yarn test

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov

Describe

.
├───.github
│   └───workflows
├───.husky
│   └───_
├───.vscode
├───assets
├───db
│   ├───migrations
│   └───seeders
├───src
│   ├───entities
│   ├───modules
│   │   ├───auth
│   │   │   ├───dto
│   │   │   └───roles
│   │   ├───database
│   │   ├───language
│   │   │   └───dto
│   │   └───user
│   │       └───dto
│   └───shared
│       ├───config
│       │   └───interfaces
│       ├───errors
│       ├───filters
│       ├───interfaces
│       ├───models
│       ├───paginate
│       │   └───interfaces
│       └───utils
└───tests
    ├───auth
    ├───database
    ├───languages
    ├───shared
    └───users

Coverage test results

To prove the source code is really good. I have set up and run unit tests almost all the functionality in the source code. below are the results.

----------------------------------|---------|----------|---------|---------|-------------------
File                              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------------------------------|---------|----------|---------|---------|-------------------
All files                         |   97.67 |    93.55 |     100 |    97.4 |                   
 src/entities                     |     100 |      100 |     100 |     100 |                   
  index.ts                        |     100 |      100 |     100 |     100 |                   
  languages.ts                    |     100 |      100 |     100 |     100 |                   
  users.ts                        |     100 |      100 |     100 |     100 |                   
 src/modules/auth                 |     100 |      100 |     100 |     100 | 
  auth.controller.ts              |     100 |      100 |     100 |     100 | 
  auth.module.ts                  |     100 |      100 |     100 |     100 | 
  auth.service.ts                 |     100 |      100 |     100 |     100 | 
  jwt-auth.guard.ts               |     100 |      100 |     100 |     100 | 
  jwt.strategy.ts                 |     100 |      100 |     100 |     100 | 
 src/modules/auth/dto             |     100 |      100 |     100 |     100 | 
  create-session.ts               |     100 |      100 |     100 |     100 | 
  update-session.ts               |     100 |      100 |     100 |     100 | 
 src/modules/auth/roles           |     100 |      100 |     100 |     100 | 
  roles.decorator.ts              |     100 |      100 |     100 |     100 | 
  roles.enum.ts                   |     100 |      100 |     100 |     100 | 
 src/modules/database             |     100 |      100 |     100 |     100 | 
  UnitOfWork.ts                   |     100 |      100 |     100 |     100 | 
  database.module.ts              |     100 |      100 |     100 |     100 | 
  database.provider.ts            |     100 |      100 |     100 |     100 | 
  repository.database.provider.ts |     100 |      100 |     100 |     100 | 
 src/modules/language             |     100 |      100 |     100 |     100 | 
  language.controller.ts          |     100 |      100 |     100 |     100 | 
  language.module.ts              |     100 |      100 |     100 |     100 | 
  language.service.ts             |     100 |      100 |     100 |     100 | 
 src/modules/language/dto         |     100 |      100 |     100 |     100 | 
  index.ts                        |     100 |      100 |     100 |     100 | 
  query-language.ts               |     100 |      100 |     100 |     100 | 
  remove-language.ts              |     100 |      100 |     100 |     100 | 
  upsert-language.ts              |     100 |      100 |     100 |     100 | 
 src/modules/user                 |     100 |      100 |     100 |     100 | 
  user.controller.ts              |     100 |      100 |     100 |     100 | 
  user.module.ts                  |     100 |      100 |     100 |     100 | 
  user.service.ts                 |     100 |      100 |     100 |     100 | 
 src/modules/user/dto             |     100 |      100 |     100 |     100 | 
  create-user.ts                  |     100 |      100 |     100 |     100 | 
  index.ts                        |     100 |      100 |     100 |     100 | 
 src/shared                       |     100 |      100 |     100 |     100 | 
  index.ts                        |     100 |      100 |     100 |     100 | 
 src/shared/config                |     100 |      100 |     100 |     100 | 
  database.ts                     |     100 |      100 |     100 |     100 | 
  error-message.ts                |     100 |      100 |     100 |     100 | 
 src/shared/errors                |     100 |      100 |     100 |     100 | 
  index.ts                        |     100 |      100 |     100 |     100 | 
  message-code-error.ts           |     100 |      100 |     100 |     100 | 
 src/shared/filters               |   76.74 |       60 |     100 |   75.61 | 
  dispatch-error.ts               |   76.74 |       60 |     100 |   75.61 | 43-52,86,105     
 src/shared/paginate              |     100 |      100 |     100 |     100 | 
  index.ts                        |     100 |      100 |     100 |     100 | 
  paginate.ts                     |     100 |      100 |     100 |     100 | 
  pagination.ts                   |     100 |      100 |     100 |     100 | 
 src/shared/utils                 |     100 |      100 |     100 |     100 | 
  crypto.ts                       |     100 |      100 |     100 |     100 | 
  reponse.ts                      |     100 |      100 |     100 |     100 | 
 tests/auth                       |     100 |      100 |     100 |     100 | 
  data-example.ts                 |     100 |      100 |     100 |     100 | 
 tests/languages                  |     100 |      100 |     100 |     100 | 
  data-example.ts                 |     100 |      100 |     100 |     100 | 
 tests/users                      |     100 |      100 |     100 |     100 | 
  data-example.ts                 |     100 |      100 |     100 |     100 | 
----------------------------------|---------|----------|---------|---------|-------------------

Test Suites: 6 passed, 6 total
Tests:       24 passed, 24 total
Snapshots:   0 total
Time:        8.371 s
Ran all test suites.
Done in 9.07s.

Support

If there is a problem in the source code, please open the Issues tab or click here. I'm really grateful to the contributors. It motivates me to go further.

Stay in touch

License

MIT licensed.