AleksandroSN / nodejs2021Q4-service_part3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 Support us

Description

Nest framework TypeScript starter repository.
Docker download Docker

Downloading

git clone {repository URL}

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Swagger

api description Available by link:

scheme://hostname:port/docs

Endpoints

  • List endpoints
    • User (/users route)
      • GET /users - get all users (remove password from response)
      • GET /users/:userId - get the user by id (ex. “/users/123”) (remove password from response)
      • POST /users - create user
      • PUT /users/:userId - update user
      • DELETE /users/:userId - delete user
    • Board (/boards route)
      • GET /boards - get all boards
      • GET /boards/:boardId - get the board by id
      • POST /boards - create board
      • PUT /boards/:boardId - update board
      • DELETE /boards/:boardId - delete board and all tasks
    • Task (/boards/:boardId/tasks route)
      • GET boards/:boardId/tasks - get all tasks
      • GET boards/:boardId/tasks/:taskId - get the task by id
      • POST boards/:boardId/tasks - create task
      • PUT boards/:boardId/tasks/:taskId - update task
      • DELETE boards/:boardId/tasks/:taskId - delete task
    • Files (/files route)
      • GET files/:filename - get one file
      • POST files - upload one or many files. RESTRICTION: TotalSize 5MB on batch of uploades files
    • Authentication (/login route)
      • POST login - authenticate in APP. Response JWT-token

FileUpload

To upload file use route : "/files".
Restrictions: TotalSize 5MB on batch of uploades files.
Multiply upload support: Yes.

Lint

npm run lint

Docker

For use ready build

docker-compose pull node-app
docker-compose pull postgres

or new build

docker-compose build

For start container use

docker-compose up -d

For shutdown container use

docker-compose down

App can be switched between Express and Fastify.
To do this :

  1. docker-compose down node-app
  2. change env USE_FASTIFY
  3. docker-compose up -d node-app
 environment:
      TYPEORM_HOST: postgres
      USE_FASTIFY: false

PostgreSQL and pgAdmin

DB : fastify-db
Tables :

  • Users
  • Tasks
  • Boards

Migrations

CLI migrations

npm run typeorm

For auto generate migrations

npm run typeorm:generate

If migrations changes

npm run typeorm:run

Docker-compose contains image dpage/pgadmin4 => pgAdmin.
To access pgadmin from docker go to http://localhost:5050.
email : admin@admin.com
password: root

To work with the pgAdmin in docker, use the next flow:

  1. Authorization (admin@admin.com / root)

  2. Add new server

    • Enter anything connection name
    • Host postgres
    • Username from .env file
    • Password from .env file
  3. Browse servers

Logger

For change level logs need go to env file and change

LOG_LEVEL

levels logs :

  • 0: error
  • 1: warn
  • 2: info
  • 3: debug
  • 4: all

if level log === 0, all errors logs write in errorLog.log

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Benchmark

In project used Artillery

Express

http.codes.200: ................................................................ 5000
http.codes.201: ................................................................ 4000
http.request_rate: ............................................................. 80/sec
http.requests: ................................................................. 9000
http.response_time:
  min: ......................................................................... 4
  max: ......................................................................... 5565
  median: ...................................................................... 982.6
  p95: ......................................................................... 3828.5
  p99: ......................................................................... 5065.6
http.responses: ................................................................ 9000
vusers.completed: .............................................................. 1000
vusers.created: ................................................................ 1000
vusers.created_by_name.NestJS API: ............................................. 1000
vusers.session_length:
  min: ......................................................................... 689.9
  max: ......................................................................... 21694.1
  median: ...................................................................... 11050.8
  p95: ......................................................................... 20958.1
  p99: ......................................................................... 21381.5

Express_benchmark

Fastify

http.codes.200: ................................................................ 5000
http.codes.201: ................................................................ 4000
http.request_rate: ............................................................. 83/sec
http.requests: ................................................................. 9000
http.response_time:
  min: ......................................................................... 1
  max: ......................................................................... 4129
  median: ...................................................................... 219.2
  p95: ......................................................................... 1826.6
  p99: ......................................................................... 3464.1
http.responses: ................................................................ 9000
vusers.completed: .............................................................. 1000
vusers.created: ................................................................ 1000
vusers.created_by_name.NestJS API: ............................................. 1000
vusers.session_length:
  min: ......................................................................... 401.9
  max: ......................................................................... 15226
  median: ...................................................................... 1587.9
  p95: ......................................................................... 14048.5
  p99: ......................................................................... 14917.2

Fastify_benchmark

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


Languages

Language:HTML 83.1%Language:TypeScript 11.7%Language:JavaScript 5.0%Language:Shell 0.1%Language:Dockerfile 0.0%