|
1 |
| -# nestjs-starter-kit |
2 |
| -NestJs starter kit with middleware and validators |
| 1 | +## NestJs Starter Kit |
| 2 | + |
| 3 | +### Overview |
| 4 | + |
| 5 | +- NestJs starter git with basic middlewares ex. logging, response structure, tracing, validation and more. |
| 6 | + |
| 7 | +- Basic setup with mysql database |
| 8 | + |
| 9 | +- Docker-compose for setting up environment |
| 10 | + |
| 11 | +### Getting Started |
| 12 | +``` |
| 13 | +npm install |
| 14 | +``` |
| 15 | + |
| 16 | +``` |
| 17 | +npm run start:dev |
| 18 | +``` |
| 19 | + |
| 20 | +## .env |
| 21 | +create a .env file in the root directory with the below variables |
| 22 | +``` |
| 23 | +POSTGRES_HOST=localhost |
| 24 | +POSTGRES_PORT=3306 |
| 25 | +POSTGRES_USER=user |
| 26 | +POSTGRES_DATABASE=db |
| 27 | +POSTGRES_PASSWORD=password |
| 28 | +``` |
| 29 | +### Swagger documentation |
| 30 | +Swagger documentation gets automatically generates, you just need to follow the conventions of entity creation. |
| 31 | + |
| 32 | +swagger url - http://localhost:3000/docs |
| 33 | + |
| 34 | +run e2e tests </br> |
| 35 | +``` |
| 36 | +npm run test:e2e |
| 37 | +``` |
| 38 | + |
| 39 | +### Creating new module |
| 40 | + |
| 41 | +To create a new module we need few things in place, we can do it either via nest-cli or manually. |
| 42 | + |
| 43 | +structure </br> |
| 44 | +module -> </br> |
| 45 | +1. *dto* -> dto_file (filename.dto.ts) (one or more)</br> |
| 46 | +Here you define your data structure to be received in request body |
| 47 | +2. *entity* -> entity_files (filename.entity.ts) (one or more) |
| 48 | +Here you define the db schema for an entity, nest picks it up and creates a table in your database using the schema defined. |
| 49 | +3. *module controller file* (module.controller.ts) |
| 50 | +Here you define your routing paths and methods to generate swagger docs for your defined path, use the ApiResponse module from swagger-ui, it will generate docs automatically for you. |
| 51 | +4. *module service file* (module.service.ts) </br> |
| 52 | +This is repository for the controllers where you call db functions. |
| 53 | +</br> |
| 54 | + |
| 55 | +Note: Remember to add any new module you have created in app.module file otherwise nest will not pickup your new module changes. |
| 56 | + |
| 57 | +### pre-commit |
| 58 | +In pre-commit we are using husky as pre-commit so no need to define any pre-commit file inside .git/config folder |
| 59 | +you can refer what's inside hook by looking package.json file, look for husky. |
| 60 | + |
| 61 | +### Docker-compose |
| 62 | +It's to run the application standalone in any environment, currently it's defines postgres as dependency and uses it's port to servce the db |
| 63 | +</br> |
| 64 | + |
| 65 | +*using docker-compose* </br> |
| 66 | + |
| 67 | +`docker-compose up` |
| 68 | + |
| 69 | +### Open issues |
0 commit comments