|
| 1 | +### NestJS |
| 2 | + |
| 3 | +Running the nestjs binary without installing it globally |
| 4 | + |
| 5 | +```bash |
| 6 | +npx -p @nestjs/cli nest |
| 7 | +``` |
| 8 | + |
| 9 | +#### Setup |
| 10 | + |
| 11 | +```bash |
| 12 | +npx -p @nestjs/cli nest new <app name> |
| 13 | +``` |
| 14 | + |
| 15 | +##### Running the [CLI](https://docs.nestjs.com/cli/overview) |
| 16 | + |
| 17 | +```bash |
| 18 | +npx nest <command> <arguments> |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | +#### Swagger documentation |
| 23 | + |
| 24 | +https://docs.nestjs.com/openapi/introduction |
| 25 | + |
| 26 | +```bash |
| 27 | +npm install @nestjs/swagger swagger-ui-express |
| 28 | +``` |
| 29 | + |
| 30 | +Setup CLI plugin |
| 31 | +https://docs.nestjs.com/openapi/cli-plugin |
| 32 | + |
| 33 | +#### Validation |
| 34 | + |
| 35 | +https://docs.nestjs.com/techniques/validation |
| 36 | + |
| 37 | +```bash |
| 38 | +npm install class-validator class-transformer |
| 39 | +npm install reflect-metadata --save |
| 40 | +``` |
| 41 | + |
| 42 | +Add `app.useGlobalPipes(new ValidationPipe({transform: true}));` |
| 43 | + |
| 44 | +uses class-validator https://github.com/typestack/class-validator |
| 45 | + |
| 46 | +#### Logging |
| 47 | + |
| 48 | +https://stackoverflow.com/questions/54101926/nestjs-middleware-get-request-response-body |
| 49 | + |
| 50 | +#### [Documentation](https://docs.nestjs.com/recipes/documentation) for the project |
| 51 | + |
| 52 | +Install |
| 53 | + |
| 54 | +```bash |
| 55 | +npm i -D @compodoc/compodoc |
| 56 | +``` |
| 57 | + |
| 58 | +npm script command: |
| 59 | + |
| 60 | +``` |
| 61 | +"doc": "compodoc -p tsconfig.json -s" |
| 62 | +``` |
| 63 | + |
| 64 | +Generate and serve documentation from port 8080 |
| 65 | + |
| 66 | +```bash |
| 67 | +npm run doc |
| 68 | +``` |
| 69 | + |
| 70 | +#### Curl |
| 71 | + |
| 72 | +```bash |
| 73 | +curl --header "Content-Type: application/json" \ |
| 74 | + --request POST \ |
| 75 | + --data '{"orderNo": "3333", "customer": {"name": "benno","age":22}, "items": [{"name": "item1", "price": 27}, {"name": "item2", "price": 99}]}' \ |
| 76 | + http://localhost:3000/ |
| 77 | + |
| 78 | +curl --header "Content-Type: application/json" \ |
| 79 | + --request POST \ |
| 80 | + --data '{"orderNo": "3333", "customer": {"name": "benno","age":22}, "items": [{"name": "item1", "price": 27, "frameSize": 55}, {"name": "item2", "price": 99, "frameSize": 45}]}' \ |
| 81 | + http://localhost:3000/ |
| 82 | + |
| 83 | +curl --header "Content-Type: application/json" \ |
| 84 | + --request POST \ |
| 85 | + --data '{"orderNo": "3333", "customer": {"name": "benno","age":22}, "items": [{"name": "item1", "price": 27, "size": "medium"}, {"name": "item2", "price": 99, "size": "medium"}]}' \ |
| 86 | + http://localhost:3001/ |
| 87 | +``` |
0 commit comments