Dự án mẫu NestJS với cấu trúc chuẩn và hỗ trợ đa cơ sở dữ liệu (MongoDB và PostgreSQL).
nest-mongodb: Hỗ trợ cơ sở dữ liệu MongoDBnest-postgresql: Hỗ trợ cơ sở dữ liệu PostgreSQL
src/
├── config/ # Configuration files
│ ├── app.config.ts # App configuration
│ └── database.config.ts # Database configuration
├── exceptions/ # Custom exception classes
├── middleware/ # Custom middleware
│ ├── logger.middleware.ts # Logging middleware
│ └── rate-limiter.middleware.ts # Rate limiting middleware
├── modules/ # Feature modules
│ └── index.txt # Module index file
├── shared/ # Shared utilities and services
│ ├── cache/ # Caching utilities
│ ├── cloudinary/ # Cloudinary integration
│ ├── mail/ # Email services
│ └── shared.module.ts # Shared module
├── app.controller.spec.ts # App controller tests
├── app.controller.ts # Main application controller
├── app.module.ts # Root module
├── app.service.ts # Main application service
└── main.ts # Application entry point
# Root level files
├── .env.example # Environment variables example
├── .eslintrc.js # ESLint configuration
├── .gitignore # Git ignore rules
├── .prettierrc # Prettier configuration
├── nest-cli.json # Nest CLI configuration
├── package.json # Node.js dependencies
├── README.md # Project documentation
├── tsconfig.build.json # TypeScript build config
├── tsconfig.json # TypeScript configuration
└── yarn.lock # Yarn lock file
- Sử dụng Mongoose để kết nối MongoDB
- Cấu hình trong
config/database.config.ts
- Sử dụng TypeORM để kết nối PostgreSQL
- Cấu hình trong
config/database.config.ts
- Chọn nhánh phù hợp:
# Cho MongoDB
git checkout nest-mongodb
# Hoặc cho PostgreSQL
git checkout nest-postgresql- Cài đặt và chạy:
npm install
npm run devLưu ý: Đảm bảo chọn đúng nhánh (nest-mongodb hoặc nest-postgresql) phù hợp với cơ sở dữ liệu bạn muốn sử dụng.