https://github.com/codegetters/nestjs-template
nestjs start template
https://github.com/codegetters/nestjs-template
Last synced: about 2 months ago
JSON representation
nestjs start template
- Host: GitHub
- URL: https://github.com/codegetters/nestjs-template
- Owner: CodeGetters
- License: mit
- Created: 2024-12-10T11:09:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-19T13:54:21.000Z (over 1 year ago)
- Last Synced: 2025-02-09T16:22:41.113Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://nestjs-template-inky.vercel.app
- Size: 308 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README-EN.md
- License: LICENSE
Awesome Lists containing this project
README
# NestJS Template
[δΈζ](README.md) | [English](README-EN.md)
A full-featured NestJS backend project template with common functionalities and best practices.
## Features
- π High-performance HTTP server based on Fastify
- π Integrated Swagger documentation (OpenAPI)
- π Global exception handling and unified response format
- π Winston logging system (with daily rotation)
- πΎ Prisma ORM integration
- β‘οΈ Request timeout handling
- β¨ Unified response transformation
- π¦’ support vercel one-click deployment
## Project Structure
```
src/
βββ api/ # API modules directory
β βββ demo/ # Example module
β βββ index.ts # API route registration
βββ common/ # Common modules
β βββ logger/ # Logging module
β βββ prisma/ # Prisma database module
βββ core/ # Core functionality
β βββ decorator/ # Custom decorators
β βββ filter/ # Exception filters
β βββ guard/ # Guards
β βββ interceptor/ # Interceptors
βββ main.ts # Application entry point
```
## Quick Start
### Requirements
- Node.js >= 16
- pnpm >= 8
### Install Dependencies
```bash
pnpm install
```
### Configure Environment Variables
```bash
cp .env.example .env
```
### Database Connection
Uncomment the code at `src/common/prisma/prisma.service.ts:51` and set up the database connection
### Start the Project
```bash
# dev
pnpm run start:dev
# prod
pnpm run start:prod
# build
pnpm run build
```
### Access Documentation
```bash
http://localhost:8080/docs
```
## One-Click Deploy
> When Vercel is deployed, an empty LoggerService will be introduced, because Vercel has its own log system, and using the original log system will cause the operation to fail.
Deploy the template using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples):
[](https://vercel.com/new/clone?repository-url=https://github.com/CodeGetters/nestjs-template)
## Main Features
### Unified Response Format
Success response format
```json
{
"code": "SUCCESS",
"data": {},
"message": "Request successful",
"timestamp": "2024-01-01T00:00:00.000Z"
}
```
Error response format
```json
{
"code": "ERROR_CODE",
"message": "Error message",
"timestamp": "2024-01-01T00:00:00.000Z",
"path": "/api/xxx"
}
```
### Logging System
- Automatic daily log file rotation
- Separate error and combined logs
- Console output in development environment
- Log files stored in logs directory
### Exception Handling
- Global exception filter for all uncaught exceptions
- HTTP exception filter for standard HTTP exceptions
- Unified handling of Prisma database exceptions
### Request Timeout Handling
Default 60-second timeout limit, configurable via TimeoutInterceptor
## Development Guide
### Adding New Modules
1. Create a new module directory in `src/api`, e.g., `user`
2. Define service in `src/api/user/user.service.ts`
3. Define controller in `src/api/user/user.controller.ts`
4. Define module in `src/api/user/user.module.ts`
5. Register new module in `src/api/index.ts`
### Using Custom Response Format
Use `@SkipTransform()` decorator to skip unified response transformation:
```typescript
@Get()
@SkipTransform()
getData() {
return { raw: 'data' };
}
```
## Contributing
Issues and Pull Requests are welcome
## License
MIT