Skip to content

NestJS REST API boilerplate with TypeORM, Jest, OAuth, Logging, Swagger docs

License

Notifications You must be signed in to change notification settings

americano212/nestjs-rest-api-boilerplate

Repository files navigation

NestJS REST API templete

Nest Logo

NestJS REST API templete with TypeORM, Jest, OAuth, Logging, Swagger docs.

Description

NestJS REST API templete(boilerplate) for quick start new project.

Support kakao & naver OAuth, common in korea.

Include example of CI/CD, deploy to AWS after testing. (by Github Actions)

🔧 Features

  • Database(TypeORM)
    • Support DB
    • MySQL
    • Postgres
  • Seeding
  • Local Authentication
  • OAuth(Social Login)
  • Customizing user's roles(Admin, User...)
  • JWT Authorization
  • Slack Alert when throw ERROR
  • Logging(winston)
  • Swagger
  • Unit Test(Jest)
  • E2E Test
  • File upload
    • Support Cloud
    • AWS S3
  • CI
  • Example Domain(Board with content)

🔨 Getting started

Configuration

# Create `.env` file with reference to `.env.example`
cp .env.example .env
  • Especially, SUPER_ADMIN will be a master account by seeding, so please decide carefully.

Init project

# 1. Install Nest CLI 
npm i -g @nestjs/cli
# 2. Install node_modules
npm ci
# 3. Setup databases by docker
npm run dev:docker:up
# 4. Load entity
npm run entity:sync
# 5. Seeding(Load Role with Super Admin)
npm run seed:run

Development

  • Set NODE_ENV='development' in .env
npm run start:dev

Production

  • Set NODE_ENV='production' in .env
npm start

Test

  • Test run on Jest.
  • Template already contains an example of unit and e2e tests.

Unit Test

# 1. Run unit test
npm run test:cov
# 2. If you debug during testing.
npm run test:debug

End-to-End Test

# 1. Run E2E test auto mode
npm run test:e2e:auto

Reset test DB

  • Erase all data in test DB
# 1. Stop test DB running
npm run test:docker:down
# 2. Run new test DB
npm run test:docker:up

Links

Database utils

# 1. When project init, synchronize Entities to Database
npm run entity:sync
# 2. [Warning] When you need to erase ALL Database, DROP ALL Exist table.
npm run entity:drop
# 3. When project init, seeding data.(Roles, Super Admin)
npm run seed:run
# 4. [Warning] When you need to erase ALL Users with roles, DELETE ALL raws in user, role, user_role table.
npm run seed:revert