Giter Site home page Giter Site logo

ts-code-test-backend's Introduction

Introduction

Create an end-to-end web application that allows the user to read, create and delete a to-do list of duties of any kind. This project is for backend.

If you are interested in frontend project, please refer to the Github Repo.

Prerequisites

(1) Please make sure Docker has already installed in your computer.

(2) Node.js(Version>=16) installed on your operating system.

Init Database and Table

Setup Database

We use PostgreSQL as database. You could use Docker to host it locally.

docker run --rm \
    --name postgres \
    -e POSTGRES_PASSWORD=Password \
    -e POSTGRES_USER=postgres \
    -e POSTGRES_DB=postgres \
    -p 5432:5432 \
    -v pgdb-vol:/var/lib/postgresql/data \
    -d \
    postgres

Alternatively, you could install it locally through the PostgreSQL official document. Or use the cloud database service directly.

Note: If you use the cloud database service directly, please update the .env of root folder config for database first.

Setup Table

Execute the sql in /sql/initDb.sql.

Install Dependencies

npm install

Or

yarn

Running Service Locally

Running without hot reload:

npm run start

Running with hot reload:

npm run start:dev

Running in debug mode:

npm run start:debug

Running other environment locally:

Update the database config in .env.qa or .env.preprod and then run the following command:

npm run build
npm run start:qa / npm run start:preprod

Due to the security issue, it's not recommended to run production in local. If you want to run production service, please refer to the next section of the document.

Running Service In the Server

It's better to run with Docker container for non-local environment.

Build Docker Image

docker build -f Dockerfile.ENV_NAME -t ts-code-test-backend:latest .

Run Docker Container

For production

docker run --rm \
    --name ts-code-test-backend \
    -p 4200:4200 \
    -e PG_HOST=PROD_HOST \
    -e PG_PORT=PROD_PORT \
    -e PG_DATABASE=PROD_DATABASE \
    -e PG_USERNAME=PROD_USERNAME \
    -e PG_PASSWORD=PROd_PASSWORD \
    -e FRONTEND_HOST=www.domain.com \
    -d \
    ts-code-test-backend:latest

For non-production

docker run --rm \
    --name ts-code-test-backend \
    -p 4200:4200 \
    -d \
    ts-code-test-backend:latest

Lint

If you want to run lint checker, please run the following command:

npm run lint

The linter also integrated with husky lib. It will check before you commit code.

Unit Test

If you want to run unit test with jest, please run the following command:

npm run test

Running with coverage report.

The result will generate to /coverage folder and then you could check the report in /coverage/lcov-report/index.html

npm run test:cov

Running with watch mode

npm run test:watch

Running with debug mode

npm run test:debug

API Specification

If you want to check Swagger API spec, please visit /api in your browser after running the project.

ts-code-test-backend's People

Contributors

llkevin13579 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.