|
1 | | -# typescript-express-template |
| 1 | +# typescript-express-template |
| 2 | + |
| 3 | +A Microservice Template in NodeJS, TypeScript, and Express |
| 4 | + |
| 5 | +Express + Routing-Controllers + TypeScript + TypeORM + TypeDI |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```shell |
| 12 | +npm install |
| 13 | +``` |
| 14 | + |
| 15 | +- Create `.env` file from `.env.example` and populate environment variables |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Running |
| 20 | + |
| 21 | +```shell |
| 22 | +# Build and Run |
| 23 | +npm start |
| 24 | + |
| 25 | +# Run on local machine with watcher |
| 26 | +npm run start:dev |
| 27 | +``` |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Features |
| 32 | + |
| 33 | +- [x] TypeScript |
| 34 | +- [x] Depedency Injection of Services, Repositories, Controllers |
| 35 | +- [x] Modular App.ts |
| 36 | +- [x] Properly structured codebase models, repositories, services, controllers, migrations etc. |
| 37 | +- [x] ORM Migrations used for maintaining database schemas |
| 38 | +- [x] Follows pure REST APIs |
| 39 | +- [x] Input validations |
| 40 | +- [x] Use of `.env` file |
| 41 | +- [x] Git pre-commit hooks setup |
| 42 | +- [x] Linting and Standard Formatting |
| 43 | +- [x] Added system metadata like createdAt, updatedAt |
| 44 | +- [x] Use of DTOs |
| 45 | +- [x] Added audit log like createdBy, updatedBy |
| 46 | +- [x] isActive |
| 47 | +- [x] uuid as primary key |
| 48 | +- [x] Soft Delete Options |
| 49 | +- [x] Pagination |
| 50 | +- [ ] Structured Logging |
| 51 | +- [ ] Unit Testing |
| 52 | +- [ ] Authentication |
| 53 | +- [ ] Authorization |
| 54 | +- [ ] Error Handling and Generic Error Middleware |
| 55 | +- [ ] Search Framework |
| 56 | +- [ ] AbstractService or interface Service |
| 57 | +- [ ] Graceful Shutdown |
| 58 | +- [x] Containerized with Docker |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Libraries Used |
| 63 | + |
| 64 | +- NodeJS with TypeScript |
| 65 | + - ts-node and ts-node-dev for running on local machine |
| 66 | +- Express Framework |
| 67 | +- TypeORM - ORM Tool to interact with Database |
| 68 | +- TypeDI - Dependency Injection library (https://github.com/typestack/typedi) |
| 69 | +- routing-controllers - For Defining Routes in elegent way (https://github.com/typestack/routing-controllers) |
| 70 | +- class-validator - For input validations (https://github.com/typestack/class-validator) |
| 71 | +- class-transformer - For transforming objects (https://github.com/typestack/class-transformer) |
| 72 | +- dotenv - Use Environment Variables from .env file |
| 73 | +- ESLint - For Linting the ES and TypeScript codebase |
| 74 | + - `ext install dbaeumer.vscode-eslint` |
| 75 | +- Prettier - For Formatting Standard (https://eslint.org/docs/user-guide/getting-started) |
| 76 | + - `ext install esbenp.prettier-vscode` |
| 77 | +- Husky - https://github.com/typicode/husky |
| 78 | +- lint-staged - https://github.com/okonet/lint-staged |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Development |
| 83 | + |
| 84 | +- Create an entity: `npm run typeorm -- entity:create -n User` |
| 85 | +- Generate migration: `npm run typeorm -- migration:generate -n CreateUser` |
| 86 | +- Run the migrations: `npm run typeorm -- migration:run` |
| 87 | + |
| 88 | +Notes: |
| 89 | + |
| 90 | +- Migration name pattern: Add<field>To<Entity> |
| 91 | + - AddLastNameToUser |
| 92 | + - UpdateEmailToEmployee |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +### Development Guidelines |
| 97 | + |
| 98 | +- Make use of `index.ts` in folder which has multiple files |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +### Development Notes |
| 103 | + |
| 104 | +```javascript |
| 105 | + |
| 106 | +``` |
0 commit comments