This NestJS starter project serves as a robust foundation for building scalable and maintainable backend applications. It incorporates best practices, essential modules, and configurations to jumpstart your development process.
- Enhanced TypeScript Configuration: Improved
tsconfig.json
for stricter type checking and better developer experience. - Environment Configuration: Utilizes
ConfigModule
for managing environment variables, including Jest setup. - Consistent HTTP Responses: Enforces a standardized structure for all HTTP responses.
- Basic HTTP Security: Implements essential security measures to protect your application.
- Request Validation: Incorporates whitelisted validation for incoming requests.
- Advanced Logging: Utilizes Winston for comprehensive logging capabilities.
- Database Setup: Docker Compose configuration for PostgreSQL and Redis.
- ORM Integration: Prisma setup for efficient database interactions.
- Caching Solution: Redis integration with a CacheService for improved performance.
- Testing Framework: Jest configuration with environment variable support.
- CI Pipeline: GitHub Actions setup for continuous integration.
The Core Module (CoreModule
) serves as the central hub for essential application-wide services and configurations. It includes:
- Global exception filters
- Interceptors for response transformation
- Logging service
- Caching service
- Database module
When extending core functionality, consider adding services or providers to this module if they are required application-wide.
This starter uses Winston for advanced logging capabilities. The LoggerService
in the Core Module provides:
- Customizable log formats for different environments
- Log levels (error, warn, info, debug, verbose)
- Context-based logging
- Metadata support for detailed log entries
To use the logger in your services or controllers, inject the LoggerService
and utilize its methods for consistent logging across your application.
-
Clone the repository:
git clone https://github.com/jfjuanmiguel/nestjs-starter.git
-
Install dependencies:
pnpm install
-
Set up your environment variables: Copy
.env.example
to.env
and fill in the required values. -
Start the development server:
pnpm start:dev
pnpm start
: Start the applicationpnpm start:dev
: Start the application in watch modepnpm test
: Run unit testspnpm test:e2e
: Run end-to-end testspnpm lint
: Lint the codebasepnpm build
: Build the applicationpnpm db:migrate:dev
: Run database migrations for developmentpnpm db:migrate:prod
: Run database migrations for production