Examples shown using TypeORM (another alternative is to use Mongoose for example)
- Create module folders, e.g.:
- notifications: dtos, infra (typeorm [schemas]), repositories, services
- Final structure:
notifications └───dtos └───infra | └───typeorm | └───repositories | └───schemas └───repositories └───services
- Create entity/schema file, e.g.:
- In
modules/notifications/infra/typeorm/schemas/
- Notifications.ts
- In
- Create repository interface, e.g.:
- In
modules/notifications/repositories/
- INotificationsRepository.ts
- In
- Create DTO (if your repository receives more than 1 data), e.g.:
- In
modules/notifications/dtos/
- ICreateNotificationDTO.ts
- In
- Create service, e.g.:
- In
modules/appointments/services/
- ListProvidersService.ts
- In
- Create TypeORM repository, e.g.:
- In
modules/notifications/infra/typeorm/repositories/
- NotificationsRepository.ts
- In
- Register NotificationsRepository.ts in
shared/container/index.ts
for dependency injection
docker run --name mongodb -p 27017:27017 -d -t mongo
- [MongoDB Compass Community]:
- "New connection"
mongodb://localhost:27017
ORmongodb://192.168.99.100:27017
(using docker with Windows)
yarn add mongodb
yarn add celebrate
[yarn add -D @types/hapi__joi
]
docker run --name redis -p 6379:6379 -d -t redis:alpine
yarn add ioredis
[@types/ioredis
]
- Create
.env
and.env.example
- Ignore
ormconfig.json
and.env
in.gitignore
- node-rate-limiter-flexible:
yarn add rate-limiter-flexible
- Using redis to save IP and number of requests in db (default save behavior: saved in memory):
yarn add redis
[@types/redis]
- Error in Test Files:
- Remember to change the dates (if necessary) in test files
- Couldn't download
redis:alpine
:- Run:
docker-machine ssh default sudo vi /etc/resolv.conf
- Press
Insert
to edit file - Change nameserver to 8.8.8.8
- Hit
ESC
andShift + Z
to save file - Restart docker service:
docker-machine restart