|
1 | | -# NestJS REST API templete v1 |
2 | | - |
3 | | -## Description |
4 | | - |
5 | | -NestJS REST API templete for Korea user. |
6 | | - |
7 | | -## Features |
8 | | - |
9 | | -- [x] Database(TypeORM) |
10 | | - - Support DB |
11 | | - - [x] MySQL |
12 | | -- [x] Seeding |
13 | | -- [x] Local Authentication |
14 | | -- [x] OAuth(Social Login) |
15 | | - - [x] Kakao |
16 | | - - [x] Naver |
17 | | - - [x] Google |
18 | | - - [x] Github |
19 | | -- [x] Customizing Roles(Admin, User...) |
20 | | -- [x] JWT Authorization |
21 | | -- [x] Slack Alert when throw ERROR |
22 | | -- [x] Logging(winston) |
23 | | -- [x] Swagger |
24 | | -- [x] Validate DTOs with Entities |
25 | | -- [x] Unit Test(Jest) |
26 | | -- [x] E2E Test |
27 | | -- [x] File upload |
28 | | -- [x] CI |
29 | | -- [x] Example Domain(Board with content) |
30 | | - |
31 | | -## Configuration |
32 | | - |
33 | | -Create `.env` file with reference to `.env.example` |
34 | | - |
35 | | -Especially, `SUPER_ADMIN` will be a master account by seeding, so please decide carefully. |
36 | | - |
37 | | -## Installation |
38 | | - |
39 | | -```bash |
40 | | -# 1. Install node_modules |
41 | | -npm ci |
42 | | -# 2. Load Entity |
43 | | -npm run entity:sync |
44 | | -# 3. Seeding(Load Role with Super Admin) |
45 | | -npm run seed:run |
46 | | -``` |
47 | | - |
48 | | -## Development |
49 | | - |
50 | | -Set `NODE_ENV='development'` in `.env` |
51 | | - |
52 | | -```bash |
53 | | -npm run start:dev |
54 | | -``` |
55 | | - |
56 | | -## Production |
57 | | - |
58 | | -Set `NODE_ENV='production'` in `.env` |
59 | | - |
60 | | -```bash |
61 | | -npm start |
62 | | -``` |
63 | | - |
64 | | -OR |
65 | | - |
66 | | -```bash |
67 | | -npm run lint |
68 | | -rimraf dist |
69 | | -nest build |
70 | | -node dist/src/main |
71 | | -``` |
72 | | - |
73 | | -## Test |
74 | | - |
75 | | -Test run on `jest`. |
76 | | -Template already contains an example of unit and e2e tests. |
77 | | - |
78 | | -### Unit Test |
79 | | - |
80 | | -```bash |
81 | | -# 1. Test by 'Jest' |
82 | | -npm run test:e2e |
83 | | -# 2. Auto e2e test. (It include creating test DB CLI too.) |
84 | | -npm run test:e2e:auto |
85 | | -``` |
86 | | - |
87 | | -### End-to-End Test |
88 | | - |
89 | | -```bash |
90 | | -# 1. Load local test DB by docker |
91 | | -npm run test:docker:up |
92 | | -# 2. Run E2E test auto mode |
93 | | -npm run test:e2e:auto |
94 | | -# 3. Quit E2E test |
95 | | -npm run test:docker:down |
96 | | -``` |
97 | | - |
98 | | -OR |
99 | | - |
100 | | -```bash |
101 | | -# 1. Load local test DB by docker |
102 | | -npm run test:docker:up |
103 | | -# 2. Initialize Database |
104 | | -npm run test:entity:drop |
105 | | -# 3. Synchronization Database |
106 | | -npm run test:entity:sync |
107 | | -# 4. Seeding Database |
108 | | -npm run test:seed:run |
109 | | -# 5. Run E2E test |
110 | | -npm run test:e2e:debug |
111 | | -# 6. Quit E2E test |
112 | | -npm run test:docker:down |
113 | | -``` |
114 | | - |
115 | | -## Links |
116 | | - |
117 | | -- Swagger: <http://localhost:8081/docs> |
118 | | - |
119 | | -## Database utils |
120 | | - |
121 | | -```bash |
122 | | -# 1. When project init, synchronize Entities to Database |
123 | | -npm run entity:sync |
124 | | -# 2. [Warning] When you need to erase ALL Database, DROP ALL Exist table. |
125 | | -npm run entity:drop |
126 | | -# 3. When project init, seeding data.(Roles, Super Admin) |
127 | | -npm run seed:run |
128 | | -# 4. [Warning] When you need to erase ALL Users with roles, DELETE ALL raws in user, role, user_role table. |
129 | | -npm run seed:revert |
130 | | -``` |
| 1 | +# NestJS REST API templete |
| 2 | +<p align="center"> |
| 3 | + <a href="https://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a> |
| 4 | +</p> |
| 5 | +<p align="center"> |
| 6 | +NestJS REST API templete with TypeORM, Jest, OAuth, Logging, Swagger docs. |
| 7 | +</p> |
| 8 | + |
| 9 | +## Description |
| 10 | +NestJS REST API templete(boilerplate) for quick start new project. |
| 11 | + |
| 12 | +Support kakao & naver OAuth, common in korea. |
| 13 | + |
| 14 | +Include example of CI/CD, deploy to AWS after testing. (by Github Actions) |
| 15 | + |
| 16 | +## 🔧 Features |
| 17 | +- [x] Database(TypeORM) |
| 18 | + - Support DB |
| 19 | + - [x] MySQL |
| 20 | + - [ ] Postgres |
| 21 | +- [x] Seeding |
| 22 | +- [x] Local Authentication |
| 23 | +- [x] OAuth(Social Login) |
| 24 | + - [x] [Kakao](https://developers.kakao.com/docs/latest/ko/kakaologin/common) |
| 25 | + - [x] [Naver](https://developers.naver.com/products/login/api/api.md) |
| 26 | + - [x] [Google](https://developers.google.com/identity/protocols/oauth2) |
| 27 | + - [x] [Github](https://docs.github.com/v3/oauth) |
| 28 | +- [x] Customizing user's roles(Admin, User...) |
| 29 | +- [x] JWT Authorization |
| 30 | +- [x] Slack Alert when throw ERROR |
| 31 | +- [x] Logging(winston) |
| 32 | +- [x] Swagger |
| 33 | +- [x] Unit Test(Jest) |
| 34 | +- [x] E2E Test |
| 35 | +- [x] File upload |
| 36 | + - Support Cloud |
| 37 | + - [x] AWS S3 |
| 38 | +- [x] CI |
| 39 | +- [x] Example Domain(Board with content) |
| 40 | + |
| 41 | +<br/> |
| 42 | + |
| 43 | +# 🔨 Getting started |
| 44 | +## Configuration |
| 45 | +```bash |
| 46 | +# Create `.env` file with reference to `.env.example` |
| 47 | +cp .env.example .env |
| 48 | +``` |
| 49 | +- Especially, `SUPER_ADMIN` will be a master account by seeding, so please decide carefully. |
| 50 | + |
| 51 | +## Init project |
| 52 | +```bash |
| 53 | +# 1. Install Nest CLI |
| 54 | +npm i -g @nestjs/cli |
| 55 | +# 2. Install node_modules |
| 56 | +npm ci |
| 57 | +# 3. Setup databases by docker |
| 58 | +npm run dev:docker:up |
| 59 | +# 4. Load entity |
| 60 | +npm run entity:sync |
| 61 | +# 5. Seeding(Load Role with Super Admin) |
| 62 | +npm run seed:run |
| 63 | +``` |
| 64 | + |
| 65 | +## Development |
| 66 | +- Set `NODE_ENV='development'` in `.env` |
| 67 | +```bash |
| 68 | +npm run start:dev |
| 69 | +``` |
| 70 | + |
| 71 | +## Production |
| 72 | +- Set `NODE_ENV='production'` in `.env` |
| 73 | +```bash |
| 74 | +npm start |
| 75 | +``` |
| 76 | + |
| 77 | +## Test |
| 78 | +- Test run on `Jest`. |
| 79 | +- Template already contains an example of `unit` and `e2e` tests. |
| 80 | + |
| 81 | +### Unit Test |
| 82 | +```bash |
| 83 | +# 1. Run unit test |
| 84 | +npm run test:cov |
| 85 | +# 2. If you debug during testing. |
| 86 | +npm run test:debug |
| 87 | +``` |
| 88 | + |
| 89 | +### End-to-End Test |
| 90 | +```bash |
| 91 | +# 1. Run E2E test auto mode |
| 92 | +npm run test:e2e:auto |
| 93 | +``` |
| 94 | + |
| 95 | +### Reset test DB |
| 96 | +- Erase all data in test DB |
| 97 | +```bash |
| 98 | +# 1. Stop test DB running |
| 99 | +npm run test:docker:down |
| 100 | +# 2. Run new test DB |
| 101 | +npm run test:docker:up |
| 102 | +``` |
| 103 | + |
| 104 | +## Links |
| 105 | + |
| 106 | +- Swagger: <http://localhost:8081/docs> |
| 107 | + |
| 108 | +## Database utils |
| 109 | + |
| 110 | +```bash |
| 111 | +# 1. When project init, synchronize Entities to Database |
| 112 | +npm run entity:sync |
| 113 | +# 2. [Warning] When you need to erase ALL Database, DROP ALL Exist table. |
| 114 | +npm run entity:drop |
| 115 | +# 3. When project init, seeding data.(Roles, Super Admin) |
| 116 | +npm run seed:run |
| 117 | +# 4. [Warning] When you need to erase ALL Users with roles, DELETE ALL raws in user, role, user_role table. |
| 118 | +npm run seed:revert |
| 119 | +``` |
0 commit comments